Animated PNG (Portable Network Graphics) is an extension to PNG format to incorporate the animations. Just like animated GIFs, the APNG format is used to present the animations. An edge of APNG over GIF is, it supports 24-bit transparency whereas GIF supports only 8-bit. Furthermore, APNG provides a smoother animation as compared to an animated GIF. In this article, I’ll show you how to create the animated PNG (APNG) images from an image or multi-page Tiff and export APNG to animated GIF programmatically using C# (or VB.NET).
- .NET API for Animated PNG Images
- Create animated PNG from an image
- Create animated PNG from multi-page Tiff file
- Export animated PNG to animated GIF
.NET API for Animated PNG Images
Aspose offers its .NET Imaging API to create or manipulate popular image formats including animated PNG using C# or VB.NET. We’ll leverage the capabilities of Aspose.Imaging for .NET to create or export animated PNG images. You can either download the API’s DLL or install it within your .NET application using NuGet.
PM> Install-Package Aspose.Imaging
Create Animated PNG from an Image using C#
Aspose.Imaging for .NET lets you create an animated PNG from a single-page image such as PNG by setting the custom animation and frame duration. The following are the steps to perform this operation.
- Load the PNG image into a RasterImage object using Image.Load(String) method.
- Set ApngOptions properties as per your requirements.
- Use the ApngImage class to create the animated PNG.
- Update the gamma of each frame using ApngFrame.AdjustGamma(Single) method.
- Create animated PNG using ApngImage.Save() method.
The following code sample shows how to create an animated PNG (APNG) from a PNG image using C#.
Create Animated PNG from Multi-Page Tiff using C#
You can also use a multi-page Tiff file to create the animated PNG by setting the desired frame time. The following are the steps to create animated PNG from a Tiff file.
- Load Tiff image within an object of Image class.
- Save Tiff as APNG using Image.Save(String, ImageOptionsBase) method.
The following code sample shows how to create animated PNG from a Tiff file using C#.
Export Animated PNG to Animated GIF using C#
You can also export an animated PNG image to an equivalent animated GIF. The following are the steps to export APNG to GIF.
- Load the animated PNG into an Image object.
- Export APNG to GIF using Image.Save(String, GifOptions()) method.
The following code sample shows how to export animated PNG to GIF using C#.
Source Animated PNG
In this article, you have learned how to create an animated PNG from different sources using C#. The step by step guide and code samples demonstrated how to create animated PNG from single-page PNG and multi-page Tiff as well as export animated PNG to an animated GIF using C#. You can learn more about manipulating APNG images using the documentation of the API.