Modern API

Introduction

Historically, Aspose Slides has a dependency on System.Drawing and has in the public API the following classes from there:

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

Since System.Drawing support in versions .NET6 and above is removed for non-Windows versions (breaking change), Slides has implemented a two library version approach:

The inconvenience of Aspose.Slides.NET6.CrossPlatform is that it implements its own version of System.Drawing in the same namespace (to support backward compatibility with the public API). Thus, when Aspose.Slides.NET6.CrossPlatform and System.Drawing from .NETFramrwork or System.Drawing.Common package are used at the same time, a name conflict occurs unless alias is used.

In order to get rid of dependencies on System.Drawing in the main Aspose.Slides.NET package, 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 the following types from System.Drawing: Image and Bitmap. PrinterSettings and Graphics are declared deprecated and their 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:

  • Aspose.Slides.IImage - represents the raster or vector image.
  • Aspose.Slides.ImageFormat - represents the file format of the image.
  • Aspose.Slides.Images - methods to instantiate and work with the IImage interface.

Please note that IImage is disposable (it implements the IDisposable interface 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:

using (Presentation pres = new Presentation())
{
    IPPImage ppImage;
    // instantiate a disposable instance of IImage from the file on the disk.  
    using (IImage image = Images.FromFile("image.png"))
    {
        // create a PowerPoint image by adding an instance of IImage to the presentation's images.
        ppImage = pres.Images.AddImage(image);
    }

    // add a picture shape on the slide #1
    pres.Slides[0].Shapes.AddPictureFrame(ShapeType.Rectangle, 10, 10, 100, 100, ppImage);

    // get an instance of the IImage representing slide #1.
    using (var slideImage = pres.Slides[0].GetImage(new Size(1920, 1080)))
    {
        // save the image on the disk.
        slideImage.Save("slide1.jpeg", ImageFormat.Jpeg);
    }
}

Replacing old code with Modern API

For ease of transition, the interface of the new IImage repeats the separate signatures of the Image and 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

Code using a deprecated API:

using (Presentation pres = new Presentation("pres.pptx"))
{
    pres.Slides[0].GetThumbnail().Save("slide1.png");
}

Modern API:

using (Presentation pres = new Presentation("pres.pptx"))
{
    pres.Slides[0].GetImage().Save("slide1.png");
}

Getting a shape thumbnail

Code using a deprecated API:

using (Presentation pres = new Presentation("pres.pptx"))
{
    pres.Slides[0].Shapes[0].GetThumbnail().Save("shape.png");
}

Modern API:

using (Presentation pres = new Presentation("pres.pptx"))
{
    pres.Slides[0].Shapes[0].GetImage().Save("shape.png");
}

Getting a presentation thumbnail

Code using a deprecated API:

using (Presentation pres = new Presentation("pres.pptx"))
{
    var bitmaps = pres.GetThumbnails(new RenderingOptions(), new Size(1980, 1028));
    try
    {
        for (var index = 0; index < bitmaps.Length; index++)
        {
            Bitmap thumbnail = bitmaps[index];
            thumbnail.Save($"slide{index}.png", ImageFormat.Png);
        }
    }
    finally
    {
        foreach (Bitmap bitmap in bitmaps)
        {
            bitmap.Dispose();
        }
    }
}

Modern API:

using (Presentation pres = new Presentation("pres.pptx"))
{
    var images = pres.GetImages(new RenderingOptions(), new Size(1980, 1028));
    try
    {
        for (var index = 0; index < images.Length; index++)
        {
            IImage thumbnail = images[index];
            thumbnail.Save($"slide{index}.png", ImageFormat.Png);
        }
    }
    finally
    {
        foreach (IImage image in images)
        {
            image.Dispose();
        }
    }
}

Adding a picture to a presentation

Code using a deprecated API:

using (Presentation pres = new Presentation())
{
    IPPImage ppImage;
    using (Image image = Image.FromFile("image.png"))
    {
        ppImage = pres.Images.AddImage(image);
    }

    pres.Slides[0].Shapes.AddPictureFrame(ShapeType.Rectangle, 10, 10, 100, 100, ppImage);
}

Modern API:

using (Presentation pres = new Presentation())
{
    IPPImage ppImage;
    using (IImage image = Aspose.Slides.Images.FromFile("image.png"))
    {
        ppImage = pres.Images.AddImage(image);
    }

    pres.Slides[0].Shapes.AddPictureFrame(ShapeType.Rectangle, 10, 10, 100, 100, ppImage);
}

Methods/properties to be removed and their replacement in Modern API

Presentation

Method Signature Replacement Method Signature
public Bitmap[] GetThumbnails(IRenderingOptions options) GetImages(IRenderingOptions options)
public Bitmap[] GetThumbnails(IRenderingOptions options, int[] slides) GetImages(IRenderingOptions options, int[] slides)
public Bitmap[] GetThumbnails(IRenderingOptions options, float scaleX, float scaleY) GetImages(IRenderingOptions options, float scaleX, float scaleY)
public Bitmap[] GetThumbnails(IRenderingOptions options, int[] slides, float scaleX, float scaleY) GetImages(IRenderingOptions options, int[] slides, float scaleX, float scaleY)
public Bitmap[] GetThumbnails(IRenderingOptions options, Size imageSize) GetImages(IRenderingOptions options, Size imageSize)
public Bitmap[] GetThumbnails(IRenderingOptions options, int[] slides, Size imageSize) GetImages(IRenderingOptions options, int[] slides, Size imageSize)
public void Save(string fname, SaveFormat format, HttpResponse response, bool showInline) Will be deleted completely
public void Save(string fname, SaveFormat format, ISaveOptions options, HttpResponse response, bool showInline) Will be deleted completely
public void Print() Will be deleted completely
public void Print(PrinterSettings printerSettings) Will be deleted completely
public void Print(string printerName) Will be deleted completely
public void Print(PrinterSettings printerSettings, string presName) Will be deleted completely

Shape

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

Slide

Method Signature Replacement Method Signature
public Bitmap GetThumbnail(float scaleX, float scaleY) GetImage(float scaleX, float scaleY)
public Bitmap GetThumbnail() GetImage
public Bitmap GetThumbnail(IRenderingOptions options) GetImage(IRenderingOptions options)
public Bitmap GetThumbnail(Size imageSize) GetImage(Size imageSize)
public Bitmap GetThumbnail(ITiffOptions options) GetImage(ITiffOptions options)
public Bitmap GetThumbnail(IRenderingOptions options, float scaleX, float scaleY) GetImage(IRenderingOptions options, float scaleX, float scaleY)
public Bitmap GetThumbnail(IRenderingOptions options, Size imageSize) GetImage(IRenderingOptions options, Size imageSize)
public void RenderToGraphics(IRenderingOptions options, Graphics graphics) Will be deleted completely
public void RenderToGraphics(IRenderingOptions options, Graphics graphics, float scaleX, float scaleY) Will be deleted completely
public void RenderToGraphics(IRenderingOptions options, Graphics graphics, Size renderingSize) Will be deleted completely

Output

Method Signature Replacement Method Signature
public IOutputFile Add(string path, Image image) Add(string path, IImage image)

ImageCollection

Method Signature Replacement Method Signature
IPPImage AddImage(Image image) AddImage(IImage image)

ImageWrapperFactory

Method Signature Replacement Method Signature
IImageWrapper CreateImageWrapper(Image image) CreateImageWrapper(IImage image)

PPImage

Method/Property Signature Replacement Method Signature
void ReplaceImage(Image newImage) ReplaceImage(IImage newImage)
Image SystemImage { get; } IImage Image { get; }

PatternFormat

Method Signature Replacement Method Signature
Bitmap GetTileImage(Color background, Color foreground) GetTile(Color background, Color foreground)
Bitmap GetTileImage(Color styleColor) GetTile(Color styleColor)

IPatternFormatEffectiveData

Method Signature Replacement Method Signature
Bitmap GetTileImage(Color background, Color foreground) GetTileIImage(SlidesImage image)

Support for Aspose.Slides.NET6.CrossPlatform will be discontinued

Following the release of Aspose.Slides.NET version 24.8, support for Aspose.Slides.NET6.CrossPlatform will be discontinued.

API support for Graphics and PrinterSettings will be discontinued

The Graphics class is not supported for cross-platform versions of .NET6 and higher. In Aspose Slides, the part of the API that uses it will be removed: Slide

Also, the part of the API that is related to printing will be removed:

Presentation: