Class ApngOptions

Class ApngOptions

Namespace: Aspose.Imaging.ImageOptions
Assembly: Aspose.Imaging.dll (25.7.0)

The API for Animated PNG (Animated Portable Network Graphics) image file formatcreation is a dynamic tool for developers seeking to generate captivatinganimated images. With customizable options such as frame duration and thenumber of times to loop, this API allows for fine-tuning animated contentaccording to specific needs. Whether creating engaging web graphics orinteractive visuals, you can leverage this API to seamlessly incorporateAPNG images with precise control over animation parameters.

public class ApngOptions : PngOptions, IDisposable, IHasXmpData, IHasMetadata, ICloneable
{
    public void SomeMethod()
    {
    }
}

Inheritance

object DisposableObject ImageOptionsBase PngOptions ApngOptions

Implements

IDisposable , IHasXmpData , IHasMetadata , ICloneable

Inherited Members

PngOptions.DefaultCompressionLevel , PngOptions.ColorType , PngOptions.Progressive , PngOptions.FilterType , PngOptions.CompressionLevel , PngOptions.PngCompressionLevel , PngOptions.BitDepth , ImageOptionsBase.Clone() , ImageOptionsBase.ReleaseManagedResources() , ImageOptionsBase.KeepMetadata , ImageOptionsBase.XmpData , ImageOptionsBase.Source , ImageOptionsBase.Palette , ImageOptionsBase.ResolutionSettings , ImageOptionsBase.VectorRasterizationOptions , ImageOptionsBase.BufferSizeHint , ImageOptionsBase.MultiPageOptions , ImageOptionsBase.FullFrame , ImageOptionsBase.ProgressEventHandler , DisposableObject.Dispose() , DisposableObject.ReleaseManagedResources() , DisposableObject.ReleaseUnmanagedResources() , DisposableObject.VerifyNotDisposed() , DisposableObject.Disposed , object.GetType() , object.MemberwiseClone() , 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;
   using (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;
   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 = apngImage.Pages[apngImage.PageCount - 1];
               float gamma = frameIndex > numOfFrames2 ? numOfFrames - frameIndex - 1 : frameIndex;
               lastFrame.AdjustGamma(gamma);
           }
           apngImage.AddFrame(sourceImage);
           apngImage.Save();
       }
   }

Constructors

ApngOptions()

Initializes a new instance of the Aspose.Imaging.ImageOptions.ApngOptions class.

public ApngOptions()
   {
   }

Properties

DefaultFrameTime

Gets or sets the default frame duration.

public uint DefaultFrameTime
    {
        get;
        set;
    }

Property Value

uint

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 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();
       }
   }

NumPlays

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

public int NumPlays
   {
      get;
      set;
   }

Property Value

int

Examples

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

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