public final class ApngImage extends RasterCachedMultipageImage implements IMultipageImageExt
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.
The following example shows how to export to APNG file format.
import com.aspose.imaging;
import com.aspose.imaging.imageoptions;
try (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
ApngOptions options = new ApngOptions();
options.setNumPlays(5);
image.save("Animation2.webp.png", options); // 5 cycles
}
| Constructor and Description |
|---|
ApngImage(ApngOptions options,
int width,
int height)
Begin working with the
ApngImage class by initializing
a new instance effortlessly. |
| Modifier and Type | Method and Description |
|---|---|
ApngFrame |
addFrame()
/**
|
void |
addFrame(RasterImage frameImage)
Effortlessly expand your frame collection by adding a new frame to the end
with this intuitive method.
|
void |
addFrame(RasterImage frameImage,
long frameTime)
Expand your frame collection seamlessly by appending a new frame to the
with this intuitive method.
|
void |
addPage(RasterImage page)
Add a new page to the image effortlessly with this intuitive method.
|
long |
getDefaultFrameTime()
Easily adjust the default frame duration for creating new frames with
this flexible property.
|
ImageOptionsBase |
getDefaultOptions(Object[] args)
Retrieve the default options effortlessly with this straightforward method.
|
long |
getFileFormat()
Quickly access information about the file format with this convenient property.
|
boolean |
getInterlaced()
Quickly determine whether this
PngImage object is interlaced
with this convenient property. |
Date |
getModifyDate(boolean useDefault)
Quickly obtain the date and time when the resource image was last modified
with this user-friendly method.
|
int |
getNumPlays()
Effortlessly control the number of times your animation loops with this
versatile property.
|
ImageOptionsBase |
getOriginalOptions()
Retrieve options based on the original file settings effortlessly with this intuitive method.
|
int |
getPageCount()
Retrieve the total number of pages in your image file effortlessly with this property.
|
Image[] |
getPages()
Effortlessly access the pages of your image with this convenient property.
|
ApngFrame |
insertFrame(int index)
Effortlessly insert a new frame into your frame collection at the specified
with this intuitive method.
|
void |
insertFrame(int index,
RasterImage frameImage)
Inserts new frame into the own frame collection at the specified index.
|
void |
insertFrame(int index,
RasterImage frameImage,
long frameTime)
Inserts new frame into the own frame collection at the specified index.
|
ApngFrame |
popFrameAt(int index)
Remove and retrieve the frame at the specified index from your frame collection
with this intuitive method.
|
void |
removeAllFrames()
Clear your frame collection by removing all frames with this intuitive method.
|
void |
removeFrameAt(int index)
Remove the frame at the specified index from your frame collection seamlessly
with this method.
|
void |
resetDefaultImage()
Remove a previously set default image with this intuitive method.
|
void |
setDefaultFrameTime(long value)
Easily adjust the default frame duration for creating new frames with
this flexible property.
|
void |
setDefaultImage(RasterImage image)
Set the specified raster image as the default image for the current animation
effortlessly with this method.
|
void |
setNumPlays(int value)
Effortlessly control the number of times your animation loops with this
versatile property.
|
adjustBrightness, adjustContrast, adjustGamma, adjustGamma, analyzePercentageDigitalSignature, binarizeBradley, binarizeBradley, binarizeFixed, binarizeOtsu, blend, cacheData, crop, crop, dither, embedDigitalSignature, filter, getBackgroundColor, getBitsPerPixel, getHeight, getImageOpacity, getMetadata, getPageExportingAction, getWidth, grayscale, hasAlpha, hasTransparentColor, isCached, isDigitalSigned, normalizeAngle, normalizeHistogram, replaceColor, replaceNonTransparentColors, resize, resize, resizeHeightProportionally, resizeWidthProportionally, rotate, rotateFlip, rotateFlipAll, setBackgroundColor, setPageExportingActionautoBrightnessContrastautoRotate, blend, blend, blend, dither, getArgb32Pixel, getDefaultArgb32Pixels, getDefaultPixels, getDefaultRawData, getDefaultRawData, getHorizontalResolution, getPixel, getPremultiplyComponents, getRawCustomColorConverter, getRawDataFormat, getRawDataSettings, getRawFallbackIndex, getRawIndexedColorConverter, getRawLineSize, getSkewAngle, getTransparentColor, getUpdateXmpData, getUseRawData, getVerticalResolution, isDigitalSigned, isRawDataAvailable, isUsePalette, loadArgb32Pixels, loadArgb64Pixels, loadCmyk32Pixels, loadCmykPixels, loadPartialArgb32Pixels, loadPartialArgb64Pixels, loadPartialPixels, loadPixels, loadRawData, loadRawData, normalizeAngle, readArgb32ScanLine, readScanLine, removeMetadata, replaceColor, replaceNonTransparentColors, rotate, saveArgb32Pixels, saveCmyk32Pixels, saveCmykPixels, savePixels, saveRawData, setArgb32Pixel, setHorizontalResolution, setPalette, setPixel, setPremultiplyComponents, setRawCustomColorConverter, setRawFallbackIndex, setRawIndexedColorConverter, setResolution, setTransparentColor, setTransparentColor, setUpdateXmpData, setUseRawData, setVerticalResolution, toBitmap, writeArgb32ScanLine, writeScanLinecanLoad, canLoad, canLoad, canLoad, canSave, create, create, create, create, create, create, create, getBounds, getBufferSizeHint, getContainer, getExifData, getFileFormat, getFileFormat, getFittingRectangle, getFittingRectangle, getInterruptMonitor, getIProgressEventHandler, getPalette, getProgressEventHandlerInfo, getProportionalHeight, getProportionalWidth, getSerializedStream, getSize, getXmpData, hasBackgroundColor, isAutoAdjustPalette, load, load, load, load, load, load, resize, resizeHeightProportionally, resizeHeightProportionally, resizeWidthProportionally, resizeWidthProportionally, save, save, save, save, save, save, save, save, setAutoAdjustPalette, setBackgroundColor, setBufferSizeHint, setExifData, setInterruptMonitor, setPalette, setXmpData, trySetMetadatagetDataStreamContainer, save, save, saveclose, dispose, getDisposedequals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetPageExportingAction, setPageExportingActiongetXmpData, setXmpDatapublic ApngImage(ApngOptions options, int width, int height)
Begin working with the ApngImage class by initializing
a new instance effortlessly. Perfect for developers seeking to start
using ApngImage objects quickly and efficiently in their projects.
options - The options.width - The width.height - The height.public long getFileFormat()
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.
getFileFormat in class ImageFileFormatpublic int getPageCount()
Retrieve the total number of pages in your image file effortlessly with this property. Ideal for developers needing quick access to page count information.
Value: The page count.getPageCount in interface IMultipageImagepublic Image[] getPages()
Effortlessly access the pages of your image with this convenient property. Perfect for developers seeking quick and easy access to individual pages for manipulation.
Value: The pages.getPages in interface IMultipageImagepublic int getNumPlays()
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.
Value: The number of times to loop.public void setNumPlays(int value)
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.
Value: The number of times to loop.public long getDefaultFrameTime()
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.
Value: The default frame duration, in milliseconds.public void setDefaultFrameTime(long value)
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.
Value: The default frame duration, in milliseconds.public boolean getInterlaced()
Quickly determine whether this PngImage object is interlaced
with this convenient property. Ideal for developers needing to check
the interlacing status of PNG images easily.
true if interlaced; otherwise, false.public ImageOptionsBase 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
DataStreamSupporter.save(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 Image.save(String, ImageOptionsBase) method as the second parameter.
getOriginalOptions in class Imagepublic ImageOptionsBase getDefaultOptions(Object[] args)
Retrieve the default options effortlessly with this straightforward method. Ideal for developers seeking quick access to default Apng image settings.
getDefaultOptions in class Imageargs - The arguments.public Date getModifyDate(boolean useDefault)
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.
getModifyDate in class RasterImageuseDefault - if set to true uses the information from FileInfo as default value.public void addPage(RasterImage page)
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.
addPage in interface IMultipageImageExtpage - The page to add.com.aspose.ms.System.ArgumentNullException - page is null.public ApngFrame 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 void addFrame(RasterImage frameImage)
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.
frameImage - The frame image.com.aspose.ms.System.ArgumentNullException - frameImage is null.public void addFrame(RasterImage frameImage, long frameTime)
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.
frameImage - The frame image.frameTime - The frame duration, in milliseconds.com.aspose.ms.System.ArgumentNullException - frameImage is null.public ApngFrame insertFrame(int index)
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.
index - The index.com.aspose.ms.System.ArgumentOutOfRangeException - index is less than 0.
or
index is greater than PageCount(IMultipageImage.getPageCount()).public void insertFrame(int index,
RasterImage frameImage)
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.
index - The index.frameImage - The frame image.com.aspose.ms.System.ArgumentOutOfRangeException - index is less than 0.
or
index is greater than PageCount(IMultipageImage.getPageCount()).com.aspose.ms.System.ArgumentNullException - frameImage is null.public void insertFrame(int index,
RasterImage frameImage,
long frameTime)
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.
index - The index.frameImage - The frame image.frameTime - The frame duration, in milliseconds.com.aspose.ms.System.ArgumentOutOfRangeException - index is less than 0.
or
index is greater than PageCount(IMultipageImage.getPageCount()).com.aspose.ms.System.ArgumentNullException - frameImage is null.public ApngFrame popFrameAt(int index)
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.
index - The index.com.aspose.ms.System.ArgumentOutOfRangeException - index is less than 0.
or
index is equal to or greater than PageCount(IMultipageImage.getPageCount()).public void removeFrameAt(int index)
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.
index - The index.com.aspose.ms.System.ArgumentOutOfRangeException - index is less than 0.
or
index is equal to or greater than PageCount(IMultipageImage.getPageCount()).public void 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 setDefaultImage(RasterImage image)
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.
image - The image.com.aspose.ms.System.ArgumentNullException - image is null.public void 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).
Copyright (c) 2008-2025 Aspose Pty Ltd. All Rights Reserved.