प्रेजेंटेशन में इमेजेज के साथ काम करना — Aspose.Slides FOSS for .NET

Aspose.Slides FOSS for .NET lets you embed images in a presentation’s shared image collection and display them on slides using PictureFrame shapes। Images को shape की background fill के रूप में भी उपयोग किया जा सकता है द्वारा FillType.Picture.


फ़ाइल से छवि जोड़ना

डिस्क से image बाइट्स लोड करें और उन्हें प्रस्तुति की image collection में जोड़ें के साथ prs.Images.AddImage().। फिर image को slide पर एक के रूप में रखें PictureFrame:

using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;

using var prs = new Presentation();
// Add the image to the shared collection
var imageData = File.ReadAllBytes("logo.png");
var img = prs.Images.AddImage(imageData);

// Place it on the slide as a PictureFrame
var slide = prs.Slides[0];
slide.Shapes.AddPictureFrame(ShapeType.Rectangle, 50, 50, 300, 200, img);

prs.Save("with-image.pptx", SaveFormat.Pptx);

चार positional arguments को AddPictureFrame() हैं: x, y, width, height पॉइंट्स में।.


स्ट्रीम से इमेज जोड़ना

यदि आपके पास stream से image डेटा है (उदा., URL से डाउनलोड किया गया या डेटाबेस से पढ़ा गया), तो इसे सीधे पास करें AddImage():

using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;

using var prs = new Presentation();
using var stream = File.OpenRead("photo.jpg");
var img = prs.Images.AddImage(stream);
prs.Slides[0].Shapes.AddPictureFrame(ShapeType.Rectangle, 100, 80, 400, 250, img);
prs.Save("from-stream.pptx", SaveFormat.Pptx);

PictureFrame की स्थिति निर्धारण और आकार निर्धारण

यह PictureFrame द्वारा लौटाया गया AddPictureFrame() सभी को विरासत में लेता है Shape ज्यामिति गुणधर्म और निर्माण के बाद पुनः स्थित किया जा सकता है:

using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;

using var prs = new Presentation();
var imageData = File.ReadAllBytes("photo.jpg");
var img = prs.Images.AddImage(imageData);

var pf = prs.Slides[0].Shapes.AddPictureFrame(ShapeType.Rectangle, 0, 0, 100, 100, img);

// Reposition and resize after creation
pf.X = 50;
pf.Y = 100;
pf.Width = 350;
pf.Height = 250;

prs.Save("positioned.pptx", SaveFormat.Pptx);

छवि को शैप फ़िल के रूप में उपयोग करना

कोई भी shape (केवल PictureFrame नहीं) एक image को अपनी background fill के रूप में उपयोग कर सकता है। Set FillType = FillType.Picture और image को असाइन करें PictureFillFormat.Picture.Image:

using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;

using var prs = new Presentation();
var imageData = File.ReadAllBytes("background.png");
var img = prs.Images.AddImage(imageData);

var slide = prs.Slides[0];
var shape = slide.Shapes.AddAutoShape(ShapeType.RoundCornerRectangle, 50, 50, 400, 250);
shape.FillFormat.FillType = FillType.Picture;
shape.FillFormat.PictureFillFormat.PictureFillMode = PictureFillMode.Stretch;
shape.FillFormat.PictureFillFormat.Picture.Image = img;

prs.Save("picture-fill.pptx", SaveFormat.Pptx);

PictureFillMode.Stretch image को स्केल करता है ताकि वह पूरे shape को भर दे।.


स्लाइड्स में कई इमेजेज जोड़ना

Images को जोड़ा गया prs.Images सभी स्लाइड्स में साझा किए जाते हैं। वही image ऑब्जेक्ट कई स्लाइड्स पर बिना डेटा डुप्लिकेट किए उपयोग किया जा सकता है:

using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;

using var prs = new Presentation();
var logoData = File.ReadAllBytes("logo.png");
var logo = prs.Images.AddImage(logoData);

// Add the same image to the first slide
prs.Slides[0].Shapes.AddPictureFrame(ShapeType.Rectangle, 600, 10, 100, 40, logo);

prs.Save("shared-image.pptx", SaveFormat.Pptx);

See Also

 हिन्दी