ImageCollection / PPImage — Aspose.Slides FOSS for .NET API Reference

The ImageCollection class manages all images embedded in a presentation, accessed via Presentation.Images. Each image is represented by a PPImage object.

Package: Aspose.Slides.Foss (net9.0)

using Aspose.Slides.Foss;

ImageCollection

public class ImageCollection : IImageCollection, IEnumerable<IPPImage>

Properties

PropertyTypeAccessDescription
CountintReadNumber of images in the collection.

Methods

MethodReturnsDescription
AddImage(IImage image)IPPImageAdd an image from an IImage instance.
AddImage(Stream stream)IPPImageAdd an image from a stream.
AddImage(byte[] buffer)IPPImageAdd an image from a byte array.

PPImage

public class PPImage : IPPImage

Properties

PropertyTypeAccessDescription
BinaryDatabyte[]ReadRaw image bytes.
ImageIImageReadImage object for rendering.
ContentTypestringReadMIME content type (e.g., image/png).
WidthintReadImage width in pixels.
HeightintReadImage height in pixels.
XintReadX offset.
YintReadY offset.

Methods

MethodDescription
ReplaceImage(byte[] newImageData)Replace the image with new binary data.
ReplaceImage(IImage newImage)Replace with a new IImage.
ReplaceImage(IPPImage newImage)Replace with another PPImage.

Image

The Image class implements IImage and IDisposable, used for saving image data.

public class Image : IImage, IDisposable

Properties

PropertyTypeAccessDescription
SizeSizeReadImage dimensions.
WidthintReadWidth in pixels.
HeightintReadHeight in pixels.

Methods

MethodDescription
Save(string filename)Save to a file.
Save(string filename, string format)Save in a specific format (e.g., "png").
Save(Stream stream, string format)Save to a stream.
Dispose()Release resources.

Usage Examples

Add an Image to a Slide

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

using var prs = new Presentation();
using var stream = File.OpenRead("logo.png");
var image = prs.Images.AddImage(stream);

prs.Slides[0].Shapes.AddPictureFrame(
    ShapeType.Rectangle, 50, 50, 200, 150, image);

Console.WriteLine($"Images in presentation: {prs.Images.Count}");
prs.Save("with-image.pptx", SaveFormat.Pptx);

Enumerate Images

using Aspose.Slides.Foss;

using var prs = new Presentation("deck.pptx");
foreach (var img in prs.Images)
{
    Console.WriteLine($"{img.ContentType}: {img.Width}x{img.Height}");
}

See Also