.NET में PowerPoint स्लाइड्स में इमेज कैसे जोड़ें
Aspose.Slides FOSS में छवियों को picture frames के रूप में एम्बेड किया जाता है, जो ऐसी आकृतियाँ हैं जो एक छवि को धारण करती हैं और अन्य किसी भी आकृति की तरह स्थित, आकार बदल और शैलीबद्ध की जा सकती हैं। छवि डेटा एक बार prs.Images संग्रह में संग्रहीत किया जाता है और फ्रेम द्वारा संदर्भित किया जाता है।
पूर्वापेक्षाएँ
dotnet add package Aspose.Slides.Fossफ़ाइल से एक छवि जोड़ें
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;
using var prs = new Presentation();
var slide = prs.Slides[0];
// Load image into the presentation's image collection
byte[] imageData = File.ReadAllBytes("photo.jpg");
var img = prs.Images.AddImage(imageData);
// Add a picture frame at (x=50, y=50, width=400, height=300) in points
var frame = slide.Shapes.AddPictureFrame(
ShapeType.Rectangle,
50, 50, 400, 300,
img
);
prs.Save("with-image.pptx", SaveFormat.Pptx);AddPictureFrame हस्ताक्षर:
AddPictureFrame(shapeType, x, y, width, height, image) -> PictureFrameसभी आयाम points में हैं (1 point = 1/72 इंच)। एक मानक 10 x 7.5 इंच स्लाइड के लिए, निर्देशांक स्थान 720 x 540 points है।
स्ट्रीम से एक छवि जोड़ें
यदि आपके पास पहले से ही छवि एक स्ट्रीम के रूप में है (उदाहरण के लिए, URL से डाउनलोड की गई या डेटाबेस से पढ़ी गई):
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;
using var prs = new Presentation();
using var stream = File.OpenRead("logo.png");
var img = prs.Images.AddImage(stream);
prs.Slides[0].Shapes.AddPictureFrame(
ShapeType.Rectangle,
200, 100, 300, 200,
img
);
prs.Save("logo-slide.pptx", SaveFormat.Pptx);फ़िल मोड को नियंत्रित करें
PictureFormat एक PictureFrame पर यह नियंत्रित करता है कि छवि फ्रेम की सीमाओं को कैसे भरती है:
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;
using var prs = new Presentation();
byte[] texData = File.ReadAllBytes("texture.png");
var img = prs.Images.AddImage(texData);
var frame = prs.Slides[0].Shapes.AddPictureFrame(
ShapeType.Rectangle, 50, 50, 600, 350, img
);
// STRETCH: scale image to fill the frame exactly (default)
frame.PictureFormat.PictureFillMode = PictureFillMode.Stretch;
// TILE: repeat the image in a grid pattern
// frame.PictureFormat.PictureFillMode = PictureFillMode.Tile;
prs.Save("filled.pptx", SaveFormat.Pptx);PictureFillMode | व्यवहार |
|---|---|
Stretch | फ़्रेम को भरने के लिए छवि को स्केल करें, अनुपात को नज़रअंदाज़ करते हुए |
Tile | छवि को टाइल पैटर्न के रूप में दोहराएँ |
विभिन्न स्लाइड्स में कई छवियां जोड़ें
using Aspose.Slides.Foss;
using Aspose.Slides.Foss.Export;
string[] imageFiles = { "slide1.jpg", "slide2.jpg", "slide3.jpg" };
using var prs = new Presentation();
var layout = prs.Slides[0].LayoutSlide;
// Ensure enough slides exist
while (prs.Slides.Count < imageFiles.Length)
prs.Slides.AddEmptySlide(layout);
for (int i = 0; i < imageFiles.Length; i++)
{
if (!File.Exists(imageFiles[i])) continue;
var img = prs.Images.AddImage(File.ReadAllBytes(imageFiles[i]));
prs.Slides[i].Shapes.AddPictureFrame(
ShapeType.Rectangle, 0, 0, 720, 540, img
);
}
prs.Save("multi-image.pptx", SaveFormat.Pptx);एक मौजूदा प्रस्तुति में छवियों की गिनती
using Aspose.Slides.Foss;
using var prs = new Presentation("with-image.pptx");
Console.WriteLine($"Presentation contains {prs.Images.Count} image(s)");prs.Images संग्रह सभी स्लाइड्स में साझा किया गया है: समान इमेज बाइट्स को केवल एक बार संग्रहीत किया जाता है, भले ही चित्र फ्रेम कई स्लाइड्स पर दिखाई दे।