Play and Pause Animated GIF and APNG Images in Web Pages using C#

GIF and APNG are from the list of most common animated image formats. GIF stands for Graphics Interchange Format and APNG files are the Animated Portable Network Graphics. If we compare GIF and APNG files of the same quality, it is noticed that APNG files are smaller in size. This article will be discussing to play and pause animated GIF and APNG files in an HTML web page using C#.

The following topics will be covered below:

.NET API for Animated Images

For the animated images, I will be using GroupDocs.Viewer for .NET API in the C# examples of this article. Along with the rendering of GIF and APNG images, this API supports rendering word-processing documents, spreadsheets, PDF, presentations, emails, ZIP archives, Visio and CAD drawings, eBooks images, programming source code files, and many other document formats.

You can download the DLLs or MSI installer from the downloads section or install the API in your .NET application via NuGet.

PM> Install-Package GroupDocs.Viewer

Play and Pause Animated APNG Images in C#

To render APNG image file to an HTML page, follow the below-mentioned steps. The C# souce code and output are also available below.

  • Create a Viewer class object with the APNG image file.
  • Create the HTMLViewOptions object using ForEmbeddedResources method, and providing it the output HTML file.
  • Call the View method of viewer object to create the view for the APNG animated image.

The following is the C# code that renders APNG image to HTML web page. It also provides the play and pause option for the animated PNG file.

Here is the view of the output HTML page with the APNG file. From this link, you can also experience the play and pause of APNG animation that is created using the above C# code.

Play / Pause APNG Animated PNG in C#

Play and Pause Animated GIF Images in C#

If you want to render the GIF images to an HTML web page, you can do it using the similar code as above. The play and pause option will also be available for GIF animations as it is for APNG animations. The following C# code example renders the GIF animation file to HTML with the play and pause option.

Conclusion

I am sure that you will be confident to give a try rendering animated GIF and APNG files to HTML web pages using C#. You can build your own .NET application having the feature to play and pause GIF and APNG animations in C#.

For more about the API and animated images, visit the documentation or the open-source examples at GitHub. Regarding any queries or confusion, feel free to contact support at the forum.

Have a nice Animated Day with C#.

See Also