Class ApngImage
Namespace: Aspose.Imaging.FileFormats.Apng
Assembly: Aspose.Imaging.dll (25.2.0)
The API for Animated PNG (Animated Portable Network Graphics) image file format is a versatile solution for developers looking to integrate animated content into their applications. This API offers extensive control over frame settings, allowing users to define frame-specific parameters, including loop duration and PNG file settings. With this feature-rich tool, you can effortlessly manage and optimize the display of APNG images, import and export images, enhancing the dynamic and interactive 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.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.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.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.```csharp [C#]
using Aspose.Imaging;
using Aspose.Imaging.ImageOptions;
using (Image image = Image.Load("img4.tif")) {
// Setting up the default frame duration
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.```csharp
[C#]
using Aspose.Imaging;
using Aspose.Imaging.ImageOptions;
using (Image image = Image.Load("Animation1.webp")) {
// Export to APNG animation with unlimited animation cycles as default
image.Save("Animation1.webp.png", new ApngOptions());
// Setting up animation cycles
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.```csharp [C#]
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 = (RasterImage)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 = (ApngImage)Image.Create(
createOptions,
sourceImage.Width,
sourceImage.Height))
{
// It is possible to set image default frame time there: apngImage.DefaultFrameTime = (uint)FrameDuration;
int numOfFrames = AnimationDuration / FrameDuration;
int numOfFrames2 = numOfFrames / 2;
// Cleaning because the image contains one frame by default
apngImage.RemoveAllFrames();
// add first frame
apngImage.AddFrame(sourceImage);
// add intermediate frames
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);
}
// add last frame
apngImage.AddFrame(sourceImage);
apngImage.Save();
}
}
## Constructors
### <a id="Aspose_Imaging_FileFormats_Apng_ApngImage__ctor_Aspose_Imaging_ImageOptions_ApngOptions_System_Int32_System_Int32_"></a> ApngImage\(ApngOptions, int, int\)
Begin working with the Aspose.Imaging.FileFormats.Apng.ApngImage class by initializing
a new instance effortlessly. Perfect for developers seeking to start
using ApngImage objects quickly and efficiently in their projects.
```csharp
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 with this flexible property. Perfect for developers seeking to customize frame timing efficiently in their animations.
public uint DefaultFrameTime { get; set; }
Property Value
Examples
The following example shows how to create APNG image from another raster single-page image.```csharp [C#]
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 = (RasterImage)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 = (ApngImage)Image.Create(
createOptions,
sourceImage.Width,
sourceImage.Height))
{
// It is possible to set image default frame time there: apngImage.DefaultFrameTime = (uint)FrameDuration;
int numOfFrames = AnimationDuration / FrameDuration;
int numOfFrames2 = numOfFrames / 2;
// Cleaning because the image contains one frame by default
apngImage.RemoveAllFrames();
// add first frame
apngImage.AddFrame(sourceImage);
// add intermediate frames
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);
}
// add last frame
apngImage.AddFrame(sourceImage);
apngImage.Save();
}
}
### <a id="Aspose_Imaging_FileFormats_Apng_ApngImage_FileFormat"></a> FileFormat
Quickly access information about the file format with this convenient property.
Ideal for developers who need to retrieve details about the format
of their Apng files easily.
```csharp
public override FileFormat FileFormat { get; }
Property Value
Interlaced
Quickly determine whether this Aspose.Imaging.FileFormats.Png.PngImage object is interlaced with this convenient property. Ideal for developers needing to check the interlacing status of PNG images easily.
public bool Interlaced { get; }
Property Value
NumPlays
Effortlessly control the number of times your animation loops with this versatile property. Perfect for developers seeking precise control over animation behavior, with support for infinite looping in case of the value equals to 0.
public int NumPlays { get; set; }
Property Value
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
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 this versatile property. Perfect for developers seeking to access or update metadata information with ease.
public override XmpPacketWrapper XmpData { get; set; }
Property Value
Methods
AddFrame()
Easily append a new frame to the end of your frame collection with this straightforward method. Ideal for developers looking to expand their frame 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()
Returns
The newly created APNG frame.
AddFrame(RasterImage)
Effortlessly expand your frame collection by adding a new frame to the end with this intuitive method. Perfect for developers seeking to enhance their animations 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.```csharp [C#]
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 = (RasterImage)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 = (ApngImage)Image.Create(
createOptions,
sourceImage.Width,
sourceImage.Height))
{
// It is possible to set image default frame time there: apngImage.DefaultFrameTime = (uint)FrameDuration;
int numOfFrames = AnimationDuration / FrameDuration;
int numOfFrames2 = numOfFrames / 2;
// Cleaning because the image contains one frame by default
apngImage.RemoveAllFrames();
// add first frame
apngImage.AddFrame(sourceImage);
// add intermediate frames
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);
}
// add last frame
apngImage.AddFrame(sourceImage);
apngImage.Save();
}
}
#### Exceptions
[ArgumentNullException](https://learn.microsoft.com/dotnet/api/system.argumentnullexception)
frameImage is null.
### <a id="Aspose_Imaging_FileFormats_Apng_ApngImage_AddFrame_Aspose_Imaging_RasterImage_System_UInt32_"></a> AddFrame\(RasterImage, uint\)
Expand your frame collection seamlessly by appending a new frame to the
with this intuitive method. Ideal for developers looking to enrich their
animations of multi-frame images.
The contents of the new frame will be filled from the specified image.
```csharp
public void AddFrame(RasterImage frameImage, uint frameTime)
Parameters
frameImage
RasterImage
The frame image.
frameTime
uint
The frame duration, in milliseconds.
Exceptions
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
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 dim
the 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.Image to make details stand out with this intuitive method. Ideal for developers seeking 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 coefficient with this intuitive method. Ideal for developers seeking precise color control in 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 channels using individual coefficients with this intuitive method. Ideal for developers seeking to 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 pixels centered 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 this intuitive 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 of 255 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 for converting 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 process to 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 this intuitive 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
Default options
GetModifyDate(bool)
Quickly obtain the date and time when the resource image was last modified with this user-friendly method. Ideal for developers needing to track changes and manage resources effectively.
public override DateTime GetModifyDate(bool useDefault)
Parameters
useDefault
bool
if set to true
uses the information from FileInfo as default value.
Returns
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 characteristics of 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 the Aspose.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 them to the Aspose.Imaging.Image.Save(System.String,Aspose.Imaging.ImageOptionsBase) method as the second parameter.
public override ImageOptionsBase GetOriginalOptions()
Returns
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 their visualization or analysis processes.
public override void Grayscale()
InsertFrame(int)
Effortlessly insert a new frame into your frame collection at the specified with this intuitive method. Ideal for developers seeking precise control over the 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)
Parameters
index
int
The index.
Returns
The newly created APNG frame.
Exceptions
index
is less than 0.
or
index
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
index
is less than 0.
or
index
is greater than Aspose.Imaging.FileFormats.Apng.ApngImage.PageCount.
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
index
is less than 0.
or
index
is greater than Aspose.Imaging.FileFormats.Apng.ApngImage.PageCount.
frameImage is null.
PopFrameAt(int)
Remove and retrieve the frame at the specified index from your frame collection with this intuitive method. Perfect for developers seeking efficient management of frames in their animations.
public ApngFrame PopFrameAt(int index)
Parameters
index
int
The index.
Returns
The removed APNG frame.
Exceptions
index
is less than 0.
or
index
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 been already released.
protected override void 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()
Examples
The following example shows how to create APNG image from another raster single-page image.```csharp [C#]
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 = (RasterImage)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 = (ApngImage)Image.Create(
createOptions,
sourceImage.Width,
sourceImage.Height))
{
// It is possible to set image default frame time there: apngImage.DefaultFrameTime = (uint)FrameDuration;
int numOfFrames = AnimationDuration / FrameDuration;
int numOfFrames2 = numOfFrames / 2;
// Cleaning because the image contains one frame by default
apngImage.RemoveAllFrames();
// add first frame
apngImage.AddFrame(sourceImage);
// add intermediate frames
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);
}
// add last frame
apngImage.AddFrame(sourceImage);
apngImage.Save();
}
}
### <a id="Aspose_Imaging_FileFormats_Apng_ApngImage_RemoveFrameAt_System_Int32_"></a> RemoveFrameAt\(int\)
Remove the frame at the specified index from your frame collection seamlessly
with this method. Perfect for developers seeking streamlined management of frames
in their multi-frame images.
The frame to be deleted will be disposed.
```csharp
public void RemoveFrameAt(int index)
Parameters
index
int
The index.
Exceptions
index
is less than 0.
or
index
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()
Resize(int, int, ResizeType)
Resize the image seamlessly with this intuitive method. Perfect for developers seeking 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 proportions with this intuitive method. Perfect for developers looking to resize images dynamically 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 while adjusting 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 changed
according to rotated rectangle (corner points) projections in other
case that leaves dimensions untouched and only
internal image contents are rotated.
backgroundColor
Color
Color of the background.
RotateFlip(RotateFlipType)
Effortlessly manipulate the active frame by rotating, flipping, or both with this intuitive method. Ideal for developers seeking to customize image 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 animation effortlessly with this method. Perfect for developers seeking to customize the default image in their animations.
public void SetDefaultImage(RasterImage image)
Parameters
image
RasterImage
The image.
Exceptions
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()