Enhance Image Processing with the Modern API

Introduction

Currently, the Aspose.Slides for C++ library has dependencies in its public API on the following classes from System::Drawing:

As of version 24.4, this public API is declared deprecated.

In order to get rid of dependencies on System::Drawing in the public API, we added the so-called “Modern API”. Methods with System::Drawing::Image and System::Drawing::Bitmap are declared deprecated and should be replaced with the corresponding methods from the Modern API. Methods with System::Drawing::Graphics are declared deprecated and have no direct Modern API replacement.

In current versions, treat the public API that depends on System::Drawing types as legacy/deprecated. Use the Modern API for new code and when migrating existing image-processing workflows.

Modern API

Added the following classes and enums to the public API:

Use GetImage to render a single slide or shape. Use GetImages to render several presentation slides. Use Images methods to load images, AddImage with IImage to add them to a presentation, and ReplaceImage with IImage to update an existing presentation image.

A typical scenario of using the new API may look as follows:

System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>();
        
// instantiate a disposable instance of IImage from the file on the disk.  
System::SharedPtr<IImage> image = Images::FromFile(u"image.png");
            
// create a PowerPoint image by adding an instance of IImage to the presentation's images.
System::SharedPtr<IPPImage> ppImage = pres->get_Images()->AddImage(image);
        
// add a picture shape on the slide #1
pres->get_Slide(0)->get_Shapes()->AddPictureFrame(Aspose::Slides::ShapeType::Rectangle, 10.0f, 10.0f, 100.0f, 100.0f, ppImage);
        
// get an instance of the IImage representing slide #1.
auto slideImage = pres->get_Slide(0)->GetImage(System::Drawing::Size(1920, 1080));

// save the image on the disk.
slideImage->Save(u"slide1.jpeg", Aspose::Slides::ImageFormat::Jpeg);

Replacing Old Code with Modern API

For ease of transition, the interface of the new IImage repeats the separate signatures of the System::Drawing::Image and System::Drawing::Bitmap classes. In general, you will just need to replace the call to the old method using System::Drawing with the new one.

Getting a Slide Thumbnail

Legacy/deprecated API:

System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");

pres->get_Slide(0)->GetThumbnail()->Save(u"slide1.png");

Modern API:

System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");

pres->get_Slide(0)->GetImage()->Save(u"slide1.png");

Getting a Shape Thumbnail

Legacy/deprecated API:

System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");

pres->get_Slide(0)->get_Shape(0)->GetThumbnail()->Save(u"shape.png");

Modern API:

System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");

pres->get_Slide(0)->get_Shape(0)->GetImage()->Save(u"shape.png");

Getting a Presentation Thumbnail

Legacy/deprecated API:

System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");

auto bitmaps = pres->GetThumbnails(System::MakeObject<RenderingOptions>(), System::Drawing::Size(1980, 1028));

for (int32_t index = 0; index < bitmaps->get_Length(); index++)
{
    System::SharedPtr<System::Drawing::Bitmap> thumbnail = bitmaps[index];
    thumbnail->Save(System::String::Format(u"slide_{0}.png", index), System::Drawing::Imaging::ImageFormat::get_Png());
}

Modern API:

System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>(u"pres.pptx");

auto images = pres->GetImages(System::MakeObject<RenderingOptions>(), System::Drawing::Size(1980, 1028));

for (int32_t index = 0; index < images->get_Length(); index++)
{
    System::SharedPtr<IImage> thumbnail = images[index];
    thumbnail->Save(System::String::Format(u"slide_{0}.png", index), Aspose::Slides::ImageFormat::Png);
}

Adding a Picture to a Presentation

Legacy/deprecated API:

System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>();

System::SharedPtr<System::Drawing::Image> image = System::Drawing::Image::FromFile(u"image.png");

System::SharedPtr<IPPImage> ppImage = pres->get_Images()->AddImage(image);

pres->get_Slide(0)->get_Shapes()->AddPictureFrame(Aspose::Slides::ShapeType::Rectangle, 10.0f, 10.0f, 100.0f, 100.0f, ppImage);

Modern API:

System::SharedPtr<Presentation> pres = System::MakeObject<Presentation>();

System::SharedPtr<Aspose::Slides::IImage> image = Aspose::Slides::Images::FromFile(u"image.png");

System::SharedPtr<IPPImage> ppImage = pres->get_Images()->AddImage(image);

pres->get_Slide(0)->get_Shapes()->AddPictureFrame(Aspose::Slides::ShapeType::Rectangle, 10.0f, 10.0f, 100.0f, 100.0f, ppImage);

Deprecated Methods/Properties and Their Replacement in Modern API

Presentation Class

Method Signature Replacement Method Signature
GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options) GetImages(System::SharedPtr<Export::IRenderingOptions> options)
GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides) GetImages(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides)
GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options, float scaleX, float scaleY) GetImages(System::SharedPtr<Export::IRenderingOptions> options, float scaleX, float scaleY)
GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides, float scaleX, float scaleY) GetImages(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides, float scaleX, float scaleY)
GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options, System::Drawing::Size imageSize) GetImages(System::SharedPtr<Export::IRenderingOptions> options, System::Drawing::Size imageSize)
GetThumbnails(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides, System::Drawing::Size imageSize) GetImages(System::SharedPtr<Export::IRenderingOptions> options, System::ArrayPtr<int32_t> slides, System::Drawing::Size imageSize)
Save(System::String fname, System::ArrayPtr<int32_t> slides, Export::SaveFormat format) No Modern API replacement
Save(System::String fname, System::ArrayPtr<int32_t> slides, Export::SaveFormat format, System::SharedPtr<Export::ISaveOptions> options) No Modern API replacement

Slide Class

Method Signature Replacement Method Signature
GetThumbnail() GetImage()
GetThumbnail(float scaleX, float scaleY) GetImage(float scaleX, float scaleY)
GetThumbnail(System::Drawing::Size imageSize) GetImage(System::Drawing::Size imageSize)
GetThumbnail(System::SharedPtr<Export::ITiffOptions> options) GetImage(System::SharedPtr<Export::IRenderingOptions> options
GetThumbnail(System::SharedPtr<Export::IRenderingOptions> options) GetImage(System::SharedPtr<Export::IRenderingOptions> options)
GetThumbnail(System::SharedPtr<Export::IRenderingOptions> options, float scaleX, float scaleY) GetImage(System::SharedPtr<Export::IRenderingOptions> options, float scaleX, float scaleY)
GetThumbnail(System::SharedPtr<Export::IRenderingOptions> options, System::Drawing::Size imageSize) GetImage(System::SharedPtr<Export::IRenderingOptions> options, System::Drawing::Size imageSize)
RenderToGraphics(System::SharedPtr<Export::IRenderingOptions> options, System::SharedPtr<System::Drawing::Graphics> graphics) No Modern API replacement
RenderToGraphics(System::SharedPtr<Export::IRenderingOptions> options, System::SharedPtr<System::Drawing::Graphics> graphics, float scaleX, float scaleY) No Modern API replacement
RenderToGraphics(System::SharedPtr<Export::IRenderingOptions> options, System::SharedPtr<System::Drawing::Graphics> graphics, System::Drawing::Size renderingSize) No Modern API replacement

Shape Class

Method Signature Replacement Method Signature
GetThumbnail() GetImage()
GetThumbnail(ShapeThumbnailBounds bounds, float scaleX, float scaleY) GetImage(ShapeThumbnailBounds bounds, float scaleX, float scaleY)

ImageCollection Class

Method Signature Replacement Method Signature
AddImage(System::SharedPtr<System::Drawing::Image> image) AddImage(System::SharedPtr<IImage> image)

PPImage Class

Method Signature Replacement Method Signature
ReplaceImage(System::SharedPtr<System::Drawing::Image> newImage) ReplaceImage(System::SharedPtr<Aspose::Slides::IImage> newImage)
get_SystemImage() get_Image()

PatternFormat Class

Method Signature Replacement Method Signature
GetTileImage(System::Drawing::Color background, System::Drawing::Color foreground) GetTile(System::Drawing::Color background, System::Drawing::Color foreground)
GetTileImage(System::Drawing::Color styleColor) GetTile(System::Drawing::Color styleColor)

IPatternFormatEffectiveData Class

Method Signature Replacement Method Signature
GetTileImage(System::Drawing::Color background, System::Drawing::Color foreground) GetTileIImage(System::Drawing::Color background, System::Drawing::Color foreground)

API Support for System::Drawing::Graphics

Methods with System::Drawing::Graphics are declared deprecated and have no direct Modern API replacement.

Use the Modern API image-rendering methods instead of the API that renders to System::Drawing::Graphics:

FAQ

Why was System::Drawing::Graphics dropped?

Support for System::Drawing::Graphics is deprecated in the public API to unify work with rendering and images, eliminate ties to platform-specific dependencies, and switch to a cross-platform approach with IImage. Use GetImage or GetImages instead of rendering to System::Drawing::Graphics.

What is the practical benefit of IImage compared to System::Drawing::Image/System::Drawing::Bitmap?

IImage unifies working with both raster and vector images, simplifies saving to various formats via ImageFormat, reduces dependence on System::Drawing, and makes code more portable across environments.

Will the Modern API affect the performance of generating thumbnails?

Switching from GetThumbnail to GetImage does not worsen scenarios: the new methods provide the same capabilities for producing images with options and sizes, while retaining support for rendering options. The specific gain or drop depends on the scenario, but functionally the replacements are equivalent.