ImageCollection — Aspose.Slides FOSS for Java API Reference

The ImageCollection class represents a collection of images embedded in a presentation. It implements IImageCollection.

Package: org.aspose.slides.foss

import org.aspose.slides.foss.*;
public class ImageCollection implements IImageCollection

Methods

MethodReturnsDescription
addImage(IImage image)IPPImageAdd an IImage to the collection.
addImage(byte[] imageData)IPPImageAdd an image from a byte array.
addImage(InputStream stream)IPPImageAdd an image from an input stream.
get(int index)IPPImageGet image by zero-based index.
size()intNumber of images in the collection.
asICollection()List<IPPImage>Return images as a List.
asIEnumerable()Iterable<IPPImage>Return images as an Iterable.
iterator()Iterator<IPPImage>Iterator over the images.

Usage Examples

Add an Image to a Presentation

import org.aspose.slides.foss.*;

Presentation prs = new Presentation();
IImage img = Images.fromFile("logo.png");
IPPImage ppImg = prs.getImages().addImage(img);

ISlide slide = prs.getSlides().get(0);
slide.getShapes().addPictureFrame(
    ShapeType.RECTANGLE, 50, 50, 200, 150, ppImg);

System.out.println("Images in presentation: " + prs.getImages().size());
prs.save("with-logo.pptx", SaveFormat.PPTX);

Add Image from Byte Array

byte[] data = Files.readAllBytes(Path.of("photo.jpg"));
IPPImage ppImg = prs.getImages().addImage(data);

See Also