Packages

 

com.aspose.imaging.fileformats.apng

Class ApngImage

  • All Implemented Interfaces:
    IMultipageImage, IMultipageImageExt, IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, com.aspose.internal.IPixelsSaver, com.aspose.internal.progressmanagement.IProgressEventHandler, com.aspose.internal.progressmanagement.IProgressInformer, com.aspose.ms.System.IDisposable, Closeable, AutoCloseable


    public final class ApngImage
    extends RasterCachedMultipageImage
    implements IMultipageImageExt

    The animated PNG image.

    Code example:

    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 Detail

      • ApngImage

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

        Initializes a new instance of the ApngImage class.

        Parameters:
        options - The options.
        width - The width.
        height - The height.
    • Method Detail

      • getFileFormat

        public long getFileFormat()

        Gets a value of file format

        Overrides:
        getFileFormat in class Image
        Returns:
        a value of file format
        See Also:
        FileFormat
      • getNumPlays

        public final int getNumPlays()

        Gets the number of times to loop animation. 0 indicates infinite looping.

        Returns:
        the number of times to loop animation.
      • setNumPlays

        public final void setNumPlays(int value)

        Sets the number of times to loop animation. 0 indicates infinite looping.

        Parameters:
        value - the number of times to loop animation.
      • getDefaultFrameTime

        public final long getDefaultFrameTime()

        Gets the default frame duration. Used when creating new frames.

        Returns:
        the default frame duration, in milliseconds.
      • setDefaultFrameTime

        public final void setDefaultFrameTime(long value)

        Sets the default frame duration. Used when creating new frames.

        Parameters:
        value - the default frame duration, in milliseconds.
      • getInterlaced

        public final boolean getInterlaced()

        Gets a value indicating whether this PngImage is interlaced.

        Returns:
        a value indicating whether this PngImage is interlaced.
      • getOriginalOptions

        public ImageOptionsBase getOriginalOptions()

        Gets the options based on the original file settings. 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.

        Overrides:
        getOriginalOptions in class Image
        Returns:
        The options based on the original file settings.
      • getModifyDate

        public Date getModifyDate(boolean useDefault)

        Gets the date and time the resource image was last modified.

        Overrides:
        getModifyDate in class RasterImage
        Parameters:
        useDefault - if set to true uses the information from FileInfo as default value.
        Returns:
        The date and time the resource image was last modified.
      • addPage

        public final void addPage(RasterImage page)

        Adds page to the image.

        Specified by:
        addPage in interface IMultipageImageExt
        Parameters:
        page - The page to add.
        Throws:
        com.aspose.ms.System.ArgumentNullException - page is null.
      • addFrame

        public final ApngFrame addFrame()

        Adds new frame to the end of the own frame collection. A new frame will be created according to the size of the current image.

        Returns:
        The newly created APNG frame.
      • addFrame

        public final void addFrame(RasterImage frameImage)

        Adds new frame to the end of the own frame collection. The contents of the new frame will be filled from the specified image.

        Parameters:
        frameImage - The frame image.
        Throws:
        com.aspose.ms.System.ArgumentNullException - frameImage is null.
      • addFrame

        public final void addFrame(RasterImage frameImage,
                                   long frameTime)

        Adds new frame to the end of the own frame collection. The contents of the new frame will be filled from the specified image.

        Parameters:
        frameImage - The frame image.
        frameTime - The frame duration, in milliseconds.
        Throws:
        com.aspose.ms.System.ArgumentNullException - frameImage is null.
      • insertFrame

        public final ApngFrame insertFrame(int index)

        Inserts new frame into the own frame collection at the specified index. A new frame will be created according to the size of the current image.

        Parameters:
        index - The index.
        Returns:
        The newly created APNG frame.
        Throws:
        com.aspose.ms.System.ArgumentOutOfRangeException - index is less than 0. or index is greater than PageCount(RasterCachedMultipageImage.getPageCount()).
      • insertFrame

        public final 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.

        Parameters:
        index - The index.
        frameImage - The frame image.
        Throws:
        com.aspose.ms.System.ArgumentOutOfRangeException - index is less than 0. or index is greater than PageCount(RasterCachedMultipageImage.getPageCount()).
        com.aspose.ms.System.ArgumentNullException - frameImage is null.
      • insertFrame

        public final 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.

        Parameters:
        index - The index.
        frameImage - The frame image.
        frameTime - The frame duration, in milliseconds.
        Throws:
        com.aspose.ms.System.ArgumentOutOfRangeException - index is less than 0. or index is greater than PageCount(RasterCachedMultipageImage.getPageCount()).
        com.aspose.ms.System.ArgumentNullException - frameImage is null.
      • popFrameAt

        public final ApngFrame popFrameAt(int index)

        Removes and returns the frame at the specified index of the own frame collection.

        Parameters:
        index - The index.
        Returns:
        The removed APNG frame.
        Throws:
        com.aspose.ms.System.ArgumentOutOfRangeException - index is less than 0. or index is equal to or greater than PageCount(RasterCachedMultipageImage.getPageCount()).
      • removeFrameAt

        public final void removeFrameAt(int index)

        Removes the frame at the specified index of the own frame collection. The frame to be deleted will be disposed.

        Parameters:
        index - The index.
        Throws:
        com.aspose.ms.System.ArgumentOutOfRangeException - index is less than 0. or index is equal to or greater than PageCount(RasterCachedMultipageImage.getPageCount()).
      • removeAllFrames

        public final void removeAllFrames()

        Removes all frames from the own frame collection.

      • setDefaultImage

        public final void setDefaultImage(RasterImage image)

        Sets the specified raster image as the default image of the current animation.

        Parameters:
        image - The image.
        Throws:
        com.aspose.ms.System.ArgumentNullException - image is null.
      • resetDefaultImage

        public final void resetDefaultImage()

        Deletes a previously set default image. After this, the default image is the first frame in the own frame collection (it cannot be deleted using this method).