Modern API
Introduction
Historically, Aspose Slides has a dependency on java.awt and has in the public API the following classes from there:
As of version 24.4, this public API is declared deprecated.
In order to get rid of dependencies on these classes, we added the so-called “Modern API” - i.e. the API that should be used instead of the deprecated one, whose signatures contain dependencies on BufferedImage. Graphics2D is declared deprecated and its support is removed from the public Slides API.
Removal of the deprecated public API with dependencies on System.Drawing will be in release 24.8.
Modern API
Added the following classes and enums to the public API:
- IImage - represents the raster or vector image.
- ImageFormat - represents the file format of the image.
- Images - methods to instantiate and work with the IImage class.
Please note that IImage is disposable (it implements the IDisposable class and its use should be wrapped in using or dispose-it in another convenient way).
A typical scenario of using the new API may look as follows:
var pres = new aspose.slides.Presentation();
try {
var ppImage;
// instantiate a disposable instance of IImage from the file on the disk.
var image = aspose.slides.Images.fromFile("image.png");
try {
// create a PowerPoint image by adding an instance of IImage to the presentation's images.
ppImage = pres.getImages().addImage(image);
} finally {
if (image != null) image.dispose();
}
// add a picture shape on the slide #1
pres.getSlides().get_Item(0).getShapes().addPictureFrame(aspose.slides.ShapeType.Rectangle, 10, 10, 100, 100, ppImage);
var size = java.newInstanceSync("java.awt.Dimension", 1920, 1080);
// get an instance of the IImage representing slide #1.
var slideImage = pres.getSlides().get_Item(0).getImage(size);
try {
// save the image on the disk.
slideImage.save("slide1.jpeg", aspose.slides.ImageFormat.Jpeg);
} finally {
if (slideImage != null) slideImage.dispose();
}
} finally {
if (pres != null) pres.dispose();
}
Replacing old code with Modern API
In general, you will need to replace the call to the old method using ImageIO with the new one.
Old:
var imageio = java.import("javax.imageio.ImageIO");
var size = java.newInstanceSync("java.awt.Dimension", 1920, 1080);
var slideImage = pres.getSlides().get_Item(0).getThumbnail(size);
var file = java.newInstanceSync("java.io.File", "image.png");
imageio.write(slideImage, "PNG", file);
New:
var size = java.newInstanceSync("java.awt.Dimension", 1920, 1080);
var slideImage = pres.getSlides().get_Item(0).getImage(size);
slideImage.save("image.png", aspose.slides.ImageFormat.Png);
slideImage.dispose();
Getting a slide thumbnail
Code using a deprecated API:
var pres = new aspose.slides.Presentation("pres.pptx");
try {
var slideImage = pres.getSlides().get_Item(0).getThumbnail();
var imageio = java.import("javax.imageio.ImageIO");
var file = java.newInstanceSync("java.io.File", "slide1.png");
imageio.write(slideImage, "PNG", file);
} finally {
if (pres != null) pres.dispose();
}
Modern API:
var pres = new aspose.slides.Presentation("pres.pptx");
try {
var slideImage = pres.getSlides().get_Item(0).getImage();
slideImage.save("slide1.png", aspose.slides.ImageFormat.Png);
slideImage.dispose();
} finally {
if (pres != null) pres.dispose();
}
Getting a shape thumbnail
Code using a deprecated API:
var pres = new aspose.slides.Presentation("pres.pptx");
try {
var shapeImage = pres.getSlides().get_Item(0).getShapes().get_Item(0).getThumbnail();
var imageio = java.import("javax.imageio.ImageIO");
var file = java.newInstanceSync("java.io.File", "shape.png");
imageio.write(shapeImage, "PNG", file);
} finally {
if (pres != null) pres.dispose();
}
Modern API:
var pres = new aspose.slides.Presentation("pres.pptx");
try {
var shapeImage = pres.getSlides().get_Item(0).getShapes().get_Item(0).getImage();
shapeImage.save("shape.png");
shapeImage.dispose();
} finally {
if (pres != null) pres.dispose();
}
Getting a presentation thumbnail
Code using a deprecated API:
var pres = new aspose.slides.Presentation("pres.pptx");
try {
var size = java.newInstanceSync("java.awt.Dimension", 1980, 1028);
var bitmaps = pres.getThumbnails(new aspose.slides.RenderingOptions(), size);
for (var index = 0; index < bitmaps.length; index++)
{
var thumbnail = bitmaps[index];
var imageio = java.import("javax.imageio.ImageIO");
var file = java.newInstanceSync("java.io.File", "slide" + index + ".png");
imageio.write(thumbnail, "PNG", file);
}
} finally {
if (pres != null) pres.dispose();
}
Modern API:
var pres = new aspose.slides.Presentation("pres.pptx");
try {
var size = java.newInstanceSync("java.awt.Dimension", 1980, 1028);
var images = pres.getImages(new aspose.slides.RenderingOptions(), size);
try
{
for (var index = 0; index < images.length; index++)
{
var thumbnail = images[index];
thumbnail.save("slide" + index + ".png", aspose.slides.ImageFormat.Png);
}
}
finally
{
images.forEach(item => {item.dispose();});
}
} finally {
if (pres != null) pres.dispose();
}
Adding a picture to a presentation
Code using a deprecated API:
var pres = new aspose.slides.Presentation();
try {
var imageio = java.import("javax.imageio.ImageIO");
var file = java.newInstanceSync("java.io.File", "image.png");
var bufferedImages = imageio.read(file);
var ppImage = pres.getImages().addImage(bufferedImages);
pres.getSlides().get_Item(0).getShapes().addPictureFrame(aspose.slides.ShapeType.Rectangle, 10, 10, 100, 100, ppImage);
} finally {
if (pres != null) pres.dispose();
}
Modern API:
var pres = new aspose.slides.Presentation();
try {
var image = aspose.slides.Images.fromFile("image.png");
var ppImage = pres.getImages().addImage(image);
image.dispose();
pres.getSlides().get_Item(0).getShapes().addPictureFrame(aspose.slides.ShapeType.Rectangle, 10, 10, 100, 100, ppImage);
} finally {
if (pres != null) pres.dispose();
}
Methods to be removed and their replacement in Modern API
Presentation
Method Signature | Replacement Method Signature |
---|---|
public final BufferedImage[] getThumbnails(IRenderingOptions options) | public final IImage[] getImages(IRenderingOptions options) |
public final BufferedImage[] getThumbnails(IRenderingOptions options, float scaleX, float scaleY) | public final IImage[] getImages(IRenderingOptions options, float scaleX, float scaleY) |
public final BufferedImage[] getThumbnails(IRenderingOptions options, int[] slides) | public final IImage[] getImages(IRenderingOptions options, int[] slides) |
public final BufferedImage[] getThumbnails(IRenderingOptions options, int[] slides, float scaleX, float scaleY) | public final IImage[] getImages(IRenderingOptions options, int[] slides, float scaleX, float scaleY) |
public final BufferedImage[] getThumbnails(IRenderingOptions options, int[] slides, Dimension imageSize) | public final IImage[] getImages(IRenderingOptions options, int[] slides, Dimension imageSize) |
public final BufferedImage[] getThumbnails(IRenderingOptions options, Dimension imageSize) | public final IImage[] getImages(IRenderingOptions options, Dimension imageSize) |
Shape
Method Signature | Replacement Method Signature |
---|---|
public final BufferedImage getThumbnail() | public final IImage getImage() |
public final BufferedImage getThumbnail(int bounds, float scaleX, float scaleY) | public final IImage getImage(int bounds, float scaleX, float scaleY) |
Slide
Method Signature | Replacement Method Signature |
---|---|
public final BufferedImage getThumbnail() | public final IImage getImage() |
public final BufferedImage getThumbnail(float scaleX, float scaleY) | public final IImage getImage(float scaleX, float scaleY) |
public final BufferedImage getThumbnail(IRenderingOptions options) | public final IImage getImage(IRenderingOptions options) |
public final BufferedImage getThumbnail(IRenderingOptions options, float scaleX, float scaleY) | public final IImage getImage(IRenderingOptions options) |
public final BufferedImage getThumbnail(IRenderingOptions options, Dimension imageSize) | public final IImage getImage(IRenderingOptions options, Dimension imageSize) |
public final BufferedImage getThumbnail(ITiffOptions options) | public final IImage getImage(ITiffOptions options) |
public final BufferedImage getThumbnail(Dimension imageSize) | public final IImage getImage(Dimension imageSize) |
public final void renderToGraphics(IRenderingOptions options, Graphics2D graphics) | Will be deleted completely |
public final void renderToGraphics(IRenderingOptions options, Graphics2D graphics, float scaleX, float scaleY) | Will be deleted completely |
public final void renderToGraphics(IRenderingOptions options, Graphics2D graphics, Dimension renderingSize) | Will be deleted completely |
Output
Method Signature | Replacement Method Signature |
---|---|
public final IOutputFile add(String path, BufferedImage image) | public final IOutputFile add(String path, IImage image) |
ImageCollection
Method Signature | Replacement Method Signature |
---|---|
public final PPImage addImage(BufferedImage image) | public final PPImage addImage(IImage image) |
PPImage
Method Signature | Replacement Method Signature |
---|---|
public final BufferedImage getSystemImage() | public final IImage getImage() |
PatternFormat
Method Signature | Replacement Method Signature |
---|---|
public final BufferedImage getTileImage(Color styleColor) | public final IImage getTile(Color styleColor) |
public final BufferedImage getTileImage(Color background, Color foreground) | public final IImage getTile(Color background, Color foreground) |
PatternFormatEffectiveData
Method Signature | Replacement Method Signature |
---|---|
public final java.awt.image.BufferedImage getTileImage(Color background, Color foreground) | public final IImage getTileIImage(Color background, Color foreground) |
API support for Graphics2D will be discontinued
Methods with Graphics2D are declared deprecated and their support will be removed from the public API.
The part of the API that uses it will be removed:
- public final void renderToGraphics(IRenderingOptions options, Graphics2D graphics)
- public final void renderToGraphics(IRenderingOptions options, Graphics2D graphics, float scaleX, float scaleY)
- public final void renderToGraphics(IRenderingOptions options, Graphics2D graphics, Dimension renderingSize)