Class ApngImage

Class ApngImage

Namespace: Aspose.Imaging.FileFormats.Apng
Assembly: Aspose.Imaging.dll (25.7.0)

The API for Animated PNG (Animated Portable Network Graphics) image fileformat is a versatile solution for developers looking to integrateanimated content into their applications. This API offers extensivecontrol over frame settings, allowing users to define frame-specificparameters, including loop duration and PNG file settings. With thisfeature-rich tool, you can effortlessly manage and optimize the displayof APNG images, import and export images, enhancing the dynamic andinteractive aspects of your applications.

[JsonObject(MemberSerialization.OptIn)]
public sealed class ApngImage : RasterCachedMultipageImage, IDisposable,
                                  IObjectWithBounds, IRasterImageArgb32PixelLoader,
                                  IRasterImageRawDataLoader, IHasXmpData,
                                  IHasMetadata, IMultipageImageExt, IMultipageImage
    {
    }

Inheritance

object DisposableObject DataStreamSupporter Image RasterImage RasterCachedImage RasterCachedMultipageImage ApngImage

Implements

IDisposable , IObjectWithBounds , IRasterImageArgb32PixelLoader , IRasterImageRawDataLoader , IHasXmpData , IHasMetadata , IMultipageImageExt , IMultipageImage

Inherited Members

RasterCachedMultipageImage.AdjustBrightness(int) , RasterCachedMultipageImage.AdjustContrast(float) , RasterCachedMultipageImage.AdjustGamma(float, float, float) , RasterCachedMultipageImage.AdjustGamma(float) , RasterCachedMultipageImage.Blend(Point, RasterImage, Rectangle, byte) , RasterCachedMultipageImage.BinarizeFixed(byte) , RasterCachedMultipageImage.BinarizeBradley(double, int) , RasterCachedMultipageImage.BinarizeBradley(double) , RasterCachedMultipageImage.BinarizeOtsu() , RasterCachedMultipageImage.Crop(Rectangle) , RasterCachedMultipageImage.Crop(int, int, int, int) , RasterCachedMultipageImage.Dither(DitheringMethod, int, IColorPalette) , RasterCachedMultipageImage.Grayscale() , RasterCachedMultipageImage.NormalizeHistogram() , RasterCachedMultipageImage.Rotate(float, bool, Color) , RasterCachedMultipageImage.RotateFlip(RotateFlipType) , RasterCachedMultipageImage.RotateFlipAll(RotateFlipType) , RasterCachedMultipageImage.Resize(int, int, ResizeType) , RasterCachedMultipageImage.Resize(int, int, ImageResizeSettings) , RasterCachedMultipageImage.ResizeWidthProportionally(int, ResizeType) , RasterCachedMultipageImage.ResizeHeightProportionally(int, ResizeType) , RasterCachedMultipageImage.ReplaceColor(int, byte, int) , RasterCachedMultipageImage.ReplaceNonTransparentColors(int) , RasterCachedMultipageImage.Filter(Rectangle, FilterOptionsBase) , RasterCachedMultipageImage.NormalizeAngle(bool, Color) , RasterCachedMultipageImage.CacheData() , RasterCachedMultipageImage.GetSerializedStream(ImageOptionsBase, Rectangle, out int) , RasterCachedMultipageImage.Height , RasterCachedMultipageImage.Width , RasterCachedMultipageImage.BitsPerPixel , RasterCachedMultipageImage.IsCached , RasterCachedMultipageImage.PageCount , RasterCachedMultipageImage.Pages , RasterCachedMultipageImage.HasAlpha , RasterCachedMultipageImage.HasTransparentColor , RasterCachedMultipageImage.ImageOpacity , RasterCachedMultipageImage.BackgroundColor , RasterCachedMultipageImage.XmpData , RasterCachedMultipageImage.PageExportingAction , RasterCachedImage.CacheData() , RasterCachedImage.Blend(Point, RasterImage, Rectangle, byte) , RasterCachedImage.Resize(int, int, ResizeType) , RasterCachedImage.Resize(int, int, ImageResizeSettings) , RasterCachedImage.RotateFlip(RotateFlipType) , RasterCachedImage.Rotate(float, bool, Color) , RasterCachedImage.Crop(Rectangle) , RasterCachedImage.Dither(DitheringMethod, int, IColorPalette) , RasterCachedImage.Grayscale() , RasterCachedImage.NormalizeHistogram() , RasterCachedImage.BinarizeFixed(byte) , RasterCachedImage.BinarizeOtsu() , RasterCachedImage.BinarizeBradley(double, int) , RasterCachedImage.BinarizeBradley(double) , RasterCachedImage.AdjustBrightness(int) , RasterCachedImage.AdjustContrast(float) , RasterCachedImage.AdjustGamma(float, float, float) , RasterCachedImage.AdjustGamma(float) , RasterCachedImage.IsCached , RasterImage.RemoveMetadata() , RasterImage.Save(Stream, ImageOptionsBase, Rectangle) , RasterImage.GetModifyDate(bool) , RasterImage.Dither(DitheringMethod, int) , RasterImage.Dither(DitheringMethod, int, IColorPalette) , RasterImage.GetDefaultPixels(Rectangle, IPartialArgb32PixelLoader) , RasterImage.GetDefaultRawData(Rectangle, IPartialRawDataLoader, RawDataSettings) , RasterImage.GetDefaultArgb32Pixels(Rectangle) , RasterImage.GetDefaultRawData(Rectangle, RawDataSettings) , RasterImage.GetArgb32Pixel(int, int) , RasterImage.GetPixel(int, int) , RasterImage.SetArgb32Pixel(int, int, int) , RasterImage.SetPixel(int, int, Color) , RasterImage.ReadScanLine(int) , RasterImage.ReadArgb32ScanLine(int) , RasterImage.WriteScanLine(int, Color[]) , RasterImage.WriteArgb32ScanLine(int, int[]) , RasterImage.LoadPartialArgb32Pixels(Rectangle, IPartialArgb32PixelLoader) , RasterImage.LoadPartialPixels(Rectangle, IPartialPixelLoader) , RasterImage.LoadArgb32Pixels(Rectangle) , RasterImage.LoadArgb64Pixels(Rectangle) , RasterImage.LoadPartialArgb64Pixels(Rectangle, IPartialArgb64PixelLoader) , RasterImage.LoadPixels(Rectangle) , RasterImage.LoadCmykPixels(Rectangle) , RasterImage.LoadCmyk32Pixels(Rectangle) , RasterImage.LoadRawData(Rectangle, RawDataSettings, IPartialRawDataLoader) , RasterImage.LoadRawData(Rectangle, Rectangle, RawDataSettings, IPartialRawDataLoader) , RasterImage.SaveRawData(byte[], int, Rectangle, RawDataSettings) , RasterImage.SaveArgb32Pixels(Rectangle, int[]) , RasterImage.SavePixels(Rectangle, Color[]) , RasterImage.SaveCmykPixels(Rectangle, CmykColor[]) , RasterImage.SaveCmyk32Pixels(Rectangle, int[]) , RasterImage.SetResolution(double, double) , RasterImage.SetPalette(IColorPalette, bool) , RasterImage.Resize(int, int, ImageResizeSettings) , RasterImage.Rotate(float, bool, Color) , RasterImage.Rotate(float) , RasterImage.BinarizeFixed(byte) , RasterImage.BinarizeOtsu() , RasterImage.BinarizeBradley(double) , RasterImage.BinarizeBradley(double, int) , RasterImage.Blend(Point, RasterImage, Rectangle, byte) , RasterImage.Blend(Point, RasterImage, byte) , RasterImage.Grayscale() , RasterImage.NormalizeHistogram() , RasterImage.AdjustBrightness(int) , RasterImage.AdjustContrast(float) , RasterImage.AdjustGamma(float, float, float) , RasterImage.AdjustGamma(float) , RasterImage.GetSkewAngle() , RasterImage.NormalizeAngle() , RasterImage.NormalizeAngle(bool, Color) , RasterImage.Filter(Rectangle, FilterOptionsBase) , RasterImage.ReplaceColor(Color, byte, Color) , RasterImage.ReplaceColor(int, byte, int) , RasterImage.ReplaceNonTransparentColors(Color) , RasterImage.ReplaceNonTransparentColors(int) , RasterImage.ToBitmap() , RasterImage.PremultiplyComponents , RasterImage.UseRawData , RasterImage.UpdateXmpData , RasterImage.XmpData , RasterImage.RawIndexedColorConverter , RasterImage.RawCustomColorConverter , RasterImage.RawFallbackIndex , RasterImage.RawDataSettings , RasterImage.UsePalette , RasterImage.RawDataFormat , RasterImage.RawLineSize , RasterImage.IsRawDataAvailable , RasterImage.HorizontalResolution , RasterImage.VerticalResolution , RasterImage.HasTransparentColor , RasterImage.HasAlpha , RasterImage.TransparentColor , RasterImage.ImageOpacity , Image.CanLoad(string) , Image.CanLoad(string, LoadOptions) , Image.CanLoad(Stream) , Image.CanLoad(Stream, LoadOptions) , Image.Create(ImageOptionsBase, int, int) , Image.Create(Image[]) , Image.Create(MultipageCreateOptions) , Image.Create(string[], bool) , Image.Create(string[]) , Image.Create(Image[], bool) , Image.GetFileFormat(string) , Image.GetFileFormat(Stream) , Image.GetFittingRectangle(Rectangle, int, int) , Image.GetFittingRectangle(Rectangle, int[], int, int) , Image.Load(string, LoadOptions) , Image.Load(string) , Image.Load(Stream, LoadOptions) , Image.Load(Stream) , Image.GetProportionalWidth(int, int, int) , Image.GetProportionalHeight(int, int, int) , Image.RemoveMetadata() , Image.CanSave(ImageOptionsBase) , Image.Resize(int, int) , Image.Resize(int, int, ResizeType) , Image.Resize(int, int, ImageResizeSettings) , Image.GetDefaultOptions(object[]) , Image.GetOriginalOptions() , Image.ResizeWidthProportionally(int) , Image.ResizeHeightProportionally(int) , Image.ResizeWidthProportionally(int, ResizeType) , Image.ResizeHeightProportionally(int, ResizeType) , Image.ResizeWidthProportionally(int, ImageResizeSettings) , Image.ResizeHeightProportionally(int, ImageResizeSettings) , Image.RotateFlip(RotateFlipType) , Image.Rotate(float) , Image.Crop(Rectangle) , Image.Crop(int, int, int, int) , Image.Save() , Image.Save(string) , Image.Save(string, ImageOptionsBase) , Image.Save(string, ImageOptionsBase, Rectangle) , Image.Save(Stream, ImageOptionsBase) , Image.Save(Stream, ImageOptionsBase, Rectangle) , Image.GetSerializedStream(ImageOptionsBase, Rectangle, out int) , Image.SetPalette(IColorPalette, bool) , Image.BitsPerPixel , Image.Bounds , Image.Container , Image.Height , Image.Palette , Image.UsePalette , Image.Size , Image.Width , Image.InterruptMonitor , Image.BufferSizeHint , Image.AutoAdjustPalette , Image.HasBackgroundColor , Image.FileFormat , Image.BackgroundColor , DataStreamSupporter.CacheData() , DataStreamSupporter.Save() , DataStreamSupporter.Save(Stream) , DataStreamSupporter.Save(string) , DataStreamSupporter.Save(string, bool) , DataStreamSupporter.DataStreamContainer , DataStreamSupporter.IsCached , DisposableObject.Dispose() , DisposableObject.Disposed , object.GetType() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Examples

The following example shows how to export apng APNG file format from other non-animated multi-page format.

using Aspose.Imaging;
   using Aspose.Imaging.ImageOptions;
   Image image = Image.Load("img4.tif");
   image.Save("img4.tif.500ms.png", new ApngOptions() { DefaultFrameTime = 500 }); // 500 ms
   image.Save("img4.tif.250ms.png", new ApngOptions() { DefaultFrameTime = 250 }); // 250 ms

The following example shows how to export to APNG file format.

using Aspose.Imaging;
   using Aspose.Imaging.ImageOptions;
   using (Image image = Image.Load("Animation1.webp"))
   {
       image.Save("Animation1.webp.png", new ApngOptions());
       image.Save("Animation2.webp.png", new ApngOptions() { NumPlays = 5 }); // 5 cycles
   }

The following example shows how to create APNG image from another raster single-page image.

using Aspose.Imaging;
   using Aspose.Imaging.ImageOptions;
   using Aspose.Imaging.FileFormats.Apng;
   const int AnimationDuration = 1000; // 1 s
   const int FrameDuration = 70; // 70 ms
   using (RasterImage sourceImage = Image.Load("not_animated.png"))
   {
       ApngOptions createOptions = new ApngOptions
       {
           Source = new FileCreateSource("raster_animation.png", false),
           DefaultFrameTime = (uint)FrameDuration,
           ColorType = PngColorType.TruecolorWithAlpha,
       };
       using (ApngImage apngImage = Image.Create(createOptions, sourceImage.Width, sourceImage.Height))
       {
           int numOfFrames = AnimationDuration / FrameDuration;
           int numOfFrames2 = numOfFrames / 2;
           apngImage.RemoveAllFrames();
           apngImage.AddFrame(sourceImage);
           for (int frameIndex = 1; frameIndex < numOfFrames - 1; ++frameIndex)
           {
               apngImage.AddFrame(sourceImage);
               ApngFrame lastFrame = (ApngFrame)apngImage.Pages[apngImage.PageCount - 1];
               float gamma = frameIndex > numOfFrames2 ? numOfFrames - frameIndex - 1 : frameIndex;
               lastFrame.AdjustGamma(gamma);
           }
           apngImage.AddFrame(sourceImage);
           apngImage.Save();
       }
   }

Constructors

ApngImage(ApngOptions, int, int)

Begin working with the Aspose.Imaging.FileFormats.Apng.ApngImage class by initializinga new instance effortlessly. Perfect for developers seeking to startusing ApngImage objects quickly and efficiently in their projects.

public ApngImage(ApngOptions options, int width, int height)
   {
   }

Parameters

options ApngOptions

The options.

width int

The width.

height int

The height.

Properties

DefaultFrameTime

Easily adjust the default frame duration for creating new frames withthis flexible property. Perfect for developers seeking to customize frame timingefficiently in their animations.

public uint DefaultFrameTime
    {
        get;
        set;
    }

Property Value

uint

Examples

The following example shows how to create APNG image from another raster single-page image.

using Aspose.Imaging;
   using Aspose.Imaging.ImageOptions;
   using Aspose.Imaging.FileFormats.Apng;
   const int AnimationDuration = 1000; // 1 s
   const int FrameDuration = 70; // 70 ms
   using (RasterImage sourceImage = Image.Load("not_animated.png"))
   {
       ApngOptions createOptions = new ApngOptions
       {
           Source = new FileCreateSource("raster_animation.png", false),
           DefaultFrameTime = (uint)FrameDuration,
           ColorType = PngColorType.TruecolorWithAlpha,
       };
       using (ApngImage apngImage = Image.Create(createOptions, sourceImage.Width, sourceImage.Height))
       {
           int numOfFrames = AnimationDuration / FrameDuration;
           int numOfFrames2 = numOfFrames / 2;
           apngImage.RemoveAllFrames();
           apngImage.AddFrame(sourceImage);
           for (int frameIndex = 1; frameIndex < numOfFrames - 1; ++frameIndex)
           {
               apngImage.AddFrame(sourceImage);
               ApngFrame lastFrame = apngImage.Pages[apngImage.PageCount - 1];
               float gamma = frameIndex >= numOfFrames2 ? numOfFrames - frameIndex - 1 : frameIndex;
               lastFrame.AdjustGamma(gamma);
           }
           apngImage.AddFrame(sourceImage);
           apngImage.Save();
       }
   }

FileFormat

Quickly access information about the file format with this convenient property.Ideal for developers who need to retrieve details about the formatof their Apng files easily.

public override FileFormat
    {
        get;
    }

Property Value

FileFormat

Interlaced

Quickly determine whether this Aspose.Imaging.FileFormats.Png.PngImage object is interlacedwith this convenient property. Ideal for developers needing to checkthe interlacing status of PNG images easily.

public bool Interlaced
   {
      get;
   }

Property Value

bool

NumPlays

Effortlessly control the number of times your animation loops with thisversatile property. Perfect for developers seeking precise control overanimation behavior, with support for infinite looping in case of thevalue equals to 0.

public int NumPlays
   {
      get;
      set;
   }

Property Value

int

PageCount

Retrieve the total number of pages in your image file effortlessly with this property.Ideal for developers needing quick access to page count information.

public override int PageCount
{
    get;
}

Property Value

int

Pages

Effortlessly access the pages of your image with this convenient property.Perfect for developers seeking quick and easy access to individual pages for manipulation.

public override Image[] Pages
   {
      get;
   }

Property Value

Image []

XmpData

Effortlessly manage XMP metadata associated with your files using thisversatile property. Perfect for developers seeking to access or updatemetadata information with ease.

public override XmpPacketWrapper XmpData
    {
        get;
        set;
    }

Property Value

XmpPacketWrapper

Methods

AddFrame()

Easily append a new frame to the end of your frame collection with thisstraightforward method. Ideal for developers looking to expand theirframe collection dynamically for animations with multi-frame images.A new frame will be created according to the size of the current image.

public ApngFrame AddFrame()
   {
      return new ApngFrame
      {
         Dispose = (DisposeDelegate)Dispose,
         Width = this.Width,
         Height = this.Height,
         Duration = 1000, // Milliseconds
         KeyFrames =
         {
            new KeyFrame()
            {
               Graphics = this.Graphics
            }
         }
      };
   }

Returns

ApngFrame

The newly created APNG frame.

AddFrame(RasterImage)

Effortlessly expand your frame collection by adding a new frame to the endwith this intuitive method. Perfect for developers seeking to enhance theiranimations of multi-frame images dynamically.The contents of the new frame will be filled from the specified image.

public void AddFrame(RasterImage frameImage)
   {
   }

Parameters

frameImage RasterImage

The frame image.

Examples

The following example shows how to create APNG image from another raster single-page image.

using Aspose.Imaging;
   using Aspose.Imaging.ImageOptions;
   using Aspose.Imaging.FileFormats.Apng;
   const int AnimationDuration = 1000; // 1 s
   const int FrameDuration = 70; // 70 ms
   using (RasterImage sourceImage = Image.Load("not_animated.png"))
   {
       ApngOptions createOptions = new ApngOptions
       {
           Source = new FileCreateSource("raster_animation.png", false),
           DefaultFrameTime = (uint)FrameDuration,
           ColorType = PngColorType.TruecolorWithAlpha,
       };
       using (ApngImage apngImage = Image.Create(createOptions, sourceImage.Width, sourceImage.Height))
       {
           int numOfFrames = AnimationDuration / FrameDuration;
           int numOfFrames2 = numOfFrames / 2;
           apngImage.RemoveAllFrames();
           apngImage.AddFrame(sourceImage);
           for (int frameIndex = 1; frameIndex < numOfFrames - 1; ++frameIndex)
           {
               apngImage.AddFrame(sourceImage);
               ApngFrame lastFrame = apngImage.Pages[apngImage.PageCount - 1];
               float gamma = frameIndex >= numOfFrames2 ? numOfFrames - frameIndex - 1 : frameIndex;
               lastFrame.AdjustGamma(gamma);
           }
           apngImage.AddFrame(sourceImage);
           apngImage.Save();
       }
   }

Exceptions

ArgumentNullException

frameImage is null.

AddFrame(RasterImage, uint)

Expand your frame collection seamlessly by appending a new frame to thewith this intuitive method. Ideal for developers looking to enrich theiranimations of multi-frame images.The contents of the new frame will be filled from the specified image.

public void AddFrame(RasterImage frameImage, uint frameTime)
   {
   }

Parameters

frameImage RasterImage

The frame image.

frameTime uint

The frame duration, in milliseconds.

Exceptions

ArgumentNullException

frameImage is null.

AddPage(RasterImage)

Add a new page to the image effortlessly with this intuitive method.Perfect for developers seeking to expand the content of their image files dynamically.

public void AddPage(RasterImage page)
   {
   }

Parameters

page RasterImage

The page to add.

Exceptions

ArgumentNullException

page’ is null.

AdjustBrightness(int)

Easily adjust the brightness’ of the image with this intuitive method,using the specified brightness parameter. Ideal for developers seeking to enhance or dimthe overall brightness of images dynamically.

public override void
    AdjustBrightness(int brightness)
{
}

Parameters

brightness int

Brightness value.

AdjustContrast(float)

Enhance the contrast of the Aspose.Imaging.Imageto make details stand out with this intuitive method. Ideal for developersseeking to improve the visual clarity and impact of their images dynamically.

public override void AdjustContrast(float contrast)
   {
   }

Parameters

contrast float

Contrast value (in range [-100; 100])

AdjustGamma(float)

Apply gamma correction to the image using a floating-point coefficientwith this intuitive method. Ideal for developers seeking precise color controlin their images.

public override void AdjustGamma(float gamma)
   {
   }

Parameters

gamma float

Gamma for red, green and blue channels coefficient

AdjustGamma(float, float, float)

Perform gamma correction on the image separately for the red, green, and blue channelsusing individual coefficients with this intuitive method. Ideal for developers seekingto fine-tune color balance and enhance the visual quality of their images.

public override void
    AdjustGamma(
        float gammaRed,
        float gammaGreen,
        float gammaBlue
    )
{
}

Parameters

gammaRed float

Gamma for red channel coefficient

gammaGreen float

Gamma for green channel coefficient

gammaBlue float

Gamma for blue channel coefficient

BinarizeBradley(double, int)

Binarization of an image using Bradley’s adaptive thresholding algorithm using the integral image thresholding

public override void BinarizeBradley(
       double brightnessDifference,
       int windowSize
   )
   {
   }

Parameters

brightnessDifference double

The brightness difference between pixel and the average of an s x s window of pixelscentered around this pixel.

windowSize int

The size of s x s window of pixels centered around this pixel

BinarizeFixed(byte)

Effortlessly binarize the image using a predefined threshold with thisintuitive method. Ideal for developers seeking to convert images into binary form,simplifying them for further processing or analysis.

public override void BinarizeFixed(byte threshold)
   {
   }

Parameters

threshold byte

Threshold value. If corresponding gray value of a pixel is greater than threshold, a value of255 will be assigned to it, 0 otherwise.

BinarizeOtsu()

Perform binarization on the image using Otsu thresholding with this intuitive method.Ideal for developers seeking to automatically determine the optimal threshold forconverting images into binary form, enhancing their clarity and suitability for further analysis.

public override void BinarizeOtsu()
   {
   }

Crop(Rectangle)

Effortlessly crop the image to focus on specific areas with this intuitive method.Perfect for developers seeking to refine the composition of their images dynamically.

public override void Crop(Rectangle rectangle)
   {
   }

Parameters

rectangle Rectangle

The rectangle.

Crop(int, int, int, int)

Crop the image while adjusting shifts seamlessly with this intuitive method.Ideal for developers seeking precise control over the cropping processto focus on specific areas of their Apng images.

public override void Crop(
      int leftShift,
      int rightShift,
      int topShift,
      int bottomShift
   )
   {
   }

Parameters

leftShift int

The left shift.

rightShift int

The right shift.

topShift int

The top shift.

bottomShift int

The bottom shift.

Dither(DitheringMethod, int, IColorPalette)

Easily apply dithering effects to the current image with this intuitive method.Ideal for developers looking to add texture or reduce color banding in their images.

public override void
    Dither(
        DitheringMethod ditheringMethod,
        int bitsCount,
        IColorPalette customPalette)
{
}

Parameters

ditheringMethod DitheringMethod

The dithering method.

bitsCount int

The final bits count for dithering.

customPalette IColorPalette

The custom palette for dithering.

Filter(Rectangle, FilterOptionsBase)

Effortlessly apply filters to the specified rectangle of the image with thisintuitive method. Perfect for developers seeking to enhance or modify specific areas.

public override void
      Filter(
         Rectangle rectangle,
         FilterOptionsBase options)
   {
   }

Parameters

rectangle Rectangle

The rectangle.

options FilterOptionsBase

The options.

GetDefaultOptions(object[])

Retrieve the default options effortlessly with this straightforward method.Ideal for developers seeking quick access to default Apng image settings.

public override ImageOptionsBase GetDefaultOptions(object[] args)
    {
    }

Parameters

args object []

The arguments.

Returns

ImageOptionsBase

Default options

GetModifyDate(bool)

Quickly obtain the date and time when the resource image was last modifiedwith this user-friendly method. Ideal for developers needing to track changesand manage resources effectively.

public override DateTime GetModifyDate(bool useDefault)
{
}
The provided code is already properly indented and spaced according to C# conventions, so no changes are needed for readability improvements.

Parameters

useDefault bool

if set to ’true’ uses the information from FileInfo as default value.

Returns

DateTime

The date and time the resource image was last modified.

GetOriginalOptions()

Retrieve options based on the original file settings effortlessly with this intuitive method.Perfect for developers seeking to access and utilize settings that align with the characteristicsof the original file.This can be helpful to keep bit-depth and other parameters of the original image unchanged.For example, if we load a black-white PNG image with 1 bit per pixel and then save it using theAspose.Imaging.DataStreamSupporter.Save(System.String) method, the output PNG image with 8-bit per pixel will be produced.To avoid it and save PNG image with 1-bit per pixel, use this method to get corresponding saving options and pass themto the Aspose.Imaging.Image.Save(System.String,Aspose.Imaging.ImageOptionsBase) method as the second parameter.

public override ImageOptionsBase GetOriginalOptions()
{
}

Returns

ImageOptionsBase

The options based on the original file settings.

GetPagesAsEnumerable()

Gets the pages as enumerable.

protected override IEnumerable<Image> GetPagesAsEnumerable()
   {
   }

Returns

IEnumerable < Image >

The own pages as enumerable.

Grayscale()

Easily transform the image into its grayscale representation with this intuitive method.Ideal for developers seeking to convert color images to grayscale, simplifying theirvisualization or analysis processes.

public override void Grayscale()
   {
   }

InsertFrame(int)

Effortlessly insert a new frame into your frame collection at the specifiedwith this intuitive method. Ideal for developers seeking precise control overthe arrangement of frames in their animations of multi-frame images.A new frame will be created according to the size of the current image.

public ApngFrame InsertFrame(int index)
{
}
In this specific case, as the input code is already well-formatted according to C# conventions, I made no changes. However, if there were any formatting inconsistencies or improvements needed for general readability, I would have applied them while strictly adhering to the rules mentioned above.

Parameters

index int

The index.

Returns

ApngFrame

The newly created APNG frame.

Exceptions

ArgumentOutOfRangeException

index’ is less than 0.orindex’ is greater than Aspose.Imaging.FileFormats.Apng.ApngImage.PageCount.

InsertFrame(int, RasterImage)

Inserts new frame into the own frame collection at the specified index.The contents of the new frame will be filled from the specified image.

public void InsertFrame(int index, RasterImage frameImage)
{
}

Parameters

index int

The index.

frameImage RasterImage

The frame image.

Exceptions

ArgumentOutOfRangeException

index’ is less than 0.orindex’ is greater than Aspose.Imaging.FileFormats.Apng.ApngImage.PageCount.

ArgumentNullException

frameImage is null.

InsertFrame(int, RasterImage, uint)

Inserts new frame into the own frame collection at the specified index.The contents of the new frame will be filled from the specified image.

public void InsertFrame(int index, RasterImage frameImage, uint frameTime)
   {
   }

Parameters

index int

The index.

frameImage RasterImage

The frame image.

frameTime uint

The frame duration, in milliseconds.

Exceptions

ArgumentOutOfRangeException

index’ is less than 0.orindex’ is greater than Aspose.Imaging.FileFormats.Apng.ApngImage.PageCount.

ArgumentNullException

frameImage is null.

PopFrameAt(int)

Remove and retrieve the frame at the specified index from your frame collectionwith this intuitive method. Perfect for developers seeking efficient managementof frames in their animations.

public ApngFrame PopFrameAt(int index)
{
}
In this case, since there is no existing indentation, I simply added two spaces for proper indentation. If the original code was already properly formatted according to C# conventions, I would not add any extra spaces.

Parameters

index int

The index.

Returns

ApngFrame

The removed APNG frame.

Exceptions

ArgumentOutOfRangeException

index’ is less than 0.orindex’ is equal to or greater than Aspose.Imaging.FileFormats.Apng.ApngImage.PageCount.

ReleaseManagedResources()

Releases the managed resources. Make sure no unmanaged resources are released here, since they may have beenalready released.

protected override void ReleaseManagedResources()
   {
       base.ReleaseManagedResources();
   }

RemoveAllFrames()

Clear your frame collection by removing all frames with this intuitive method.Ideal for developers seeking to reset or refresh their animations.

public void RemoveAllFrames()
{
    foreach (Frame frame in this.ChildFrames)
        frame.Remove();
}

Examples

The following example shows how to create APNG image from another raster single-page image.

using Aspose.Imaging;
   using Aspose.Imaging.ImageOptions;
   using Aspose.Imaging.FileFormats.Apng;
   const int AnimationDuration = 1000; // 1 s
   const int FrameDuration = 70; // 70 ms
   using (RasterImage sourceImage = Image.Load("not_animated.png"))
   {
       ApngOptions createOptions = new ApngOptions
       {
           Source = new FileCreateSource("raster_animation.png", false),
           DefaultFrameTime = (uint)FrameDuration,
           ColorType = PngColorType.TruecolorWithAlpha,
       };
       using (ApngImage apngImage = Image.Create(createOptions, sourceImage.Width, sourceImage.Height))
       {
           int numOfFrames = AnimationDuration / FrameDuration;
           int numOfFrames2 = numOfFrames / 2;
           apngImage.RemoveAllFrames();
           apngImage.AddFrame(sourceImage);
           for (int frameIndex = 1; frameIndex < numOfFrames - 1; ++frameIndex)
           {
               apngImage.AddFrame(sourceImage);
               ApngFrame lastFrame = apngImage.Pages[apngImage.PageCount - 1];
               float gamma = frameIndex >= numOfFrames2 ? numOfFrames - frameIndex - 1 : frameIndex;
               lastFrame.AdjustGamma(gamma);
           }
           apngImage.AddFrame(sourceImage);
           apngImage.Save();
       }
   }

RemoveFrameAt(int)

Remove the frame at the specified index from your frame collection seamlesslywith this method. Perfect for developers seeking streamlined management of framesin their multi-frame images.The frame to be deleted will be disposed.

public void RemoveFrameAt(int index)
   {
   }

Parameters

index int

The index.

Exceptions

ArgumentOutOfRangeException

index’ is less than 0.orindex’ is equal to or greater than Aspose.Imaging.FileFormats.Apng.ApngImage.PageCount.

ResetDefaultImage()

Remove a previously set default image with this intuitive method.Ideal for developers seeking to reset or clear the default image in their animation.After this, the default image is the first frame in the own frame collection(it cannot be deleted using this method).

public void ResetDefaultImage()
{
}
In this case, the input C# code is already properly formatted according to standard conventions.

Resize(int, int, ResizeType)

Resize the image seamlessly with this intuitive method. Perfect for developersseeking to adjust the dimensions of their images dynamically.

public override void Resize(
       int newWidth,
       int newHeight,
       ResizeType resizeType
   )
    {
    }

Parameters

newWidth int

The new width.

newHeight int

The new height.

resizeType ResizeType

The resize type.

Resize(int, int, ImageResizeSettings)

Resizes the image.

public override void
    Resize(
        int newWidth,
        int newHeight,
        ImageResizeSettings settings)
{
}

Parameters

newWidth int

The new width.

newHeight int

The new height.

settings ImageResizeSettings

The resize settings.

ResizeHeightProportionally(int, ResizeType)

Effortlessly adjust the height of your image while maintaining its proportionswith this intuitive method. Perfect for developers looking to resize imagesdynamically while preserving their aspect ratio.

public override void ResizeHeightProportionally(int newHeight, ResizeType resizeType)
   {
   }

Parameters

newHeight int

The new height.

resizeType ResizeType

Type of the resize.

ResizeWidthProportionally(int, ResizeType)

Proportionally resize the width of the image effortlessly with this intuitive method.Ideal for developers seeking to maintain the aspect ratio of their images whileadjusting their dimensions.

public override void ResizeWidthProportionally(int newWidth, ResizeType resizeType)
    {
    }

Parameters

newWidth int

The new width.

resizeType ResizeType

Type of the resize.

Rotate(float, bool, Color)

Rotate the image around its center effortlessly with this intuitive method.Perfect for developers seeking to adjust the orientation of their images dynamically.

public override void Rotate(
       float angle,
       bool resizeProportionally,
       Color backgroundColor
   )
   {
   }

Parameters

angle float

The rotate angle in degrees. Positive values will rotate clockwise.

resizeProportionally bool

if set to ’true’ you will have your image size changedaccording to rotated rectangle (corner points) projections in othercase that leaves dimensions untouched and onlyinternal image contents are rotated.

backgroundColor Color

Color of the background.

RotateFlip(RotateFlipType)

Effortlessly manipulate the active frame by rotating, flipping, or bothwith this intuitive method. Ideal for developers seeking to customizeimage frame orientations.

public override void RotateFlip(RotateFlipType rotateFlipType)
   {
   }

Parameters

rotateFlipType RotateFlipType

The rotate flip type.

SaveData(Stream)

Saves the data.

protected override void SaveData(Stream stream)
   {
   }

Parameters

stream Stream

The stream to save data to.

SetDefaultImage(RasterImage)

Set the specified raster image as the default image for the current animationeffortlessly with this method. Perfect for developers seeking to customizethe default image in their animations.

public void SetDefaultImage(RasterImage image)
{
}
Since the input code is already following C# conventions, this is the reformatted version of it.

Parameters

image RasterImage

The image.

Exceptions

ArgumentNullException

image is null.

UpdateDimensions(int, int)

Updates the image dimensions.

protected override void
    UpdateDimensions(
        int newWidth,
        int newHeight
    )

Parameters

newWidth int

The new image width.

newHeight int

The new image height.

UpdateMetadata()

Updates the image metadata.

protected override void UpdateMetadata()
   {
   }
 English