Click here to Skip to main content
11,934,425 members (52,743 online)
Click here to Skip to main content
Add your own
alternative version


35 bookmarked

APNG Viewer

, , 6 May 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
Parse and extract APNG frames to each PNG file


APNG stands for animated PNG, which is similar to gif89, but gif89 only has 256 colors, so APNG might be a better choice in some scenarios. The APNG Viewer is based on the excellent .NET MNG Viewer written by SprinterDave, all credits go to him. It uses pure C#, without any third-party components, and with a very small footprint (only 30K).


I've been searching for a native .NET APNG parser/viewer, but unfortunately, as what I have encountered before writing DBX Parser, I just could not find it (what the heck with Google, er?), so I had to do it by myself.

File Format

There are quite a few articles you might need to read in order to know what is APNG:

APNG is only a small extension to PNG, and it's compatible with PNG, so browsers like Internet Explorer and other viewers that do not support APNG will still display the first frame. Here we could see a diagram that could give us a brief idea of APNG file format:

Samples Files

Other Languages

Maybe you are looking for other languages. Here goes:

How It Works

It reads chunk by chunk as .NET MNG Viewer does, rebuilds each PNG frame according to the base header. If you look closer at the file format, you will find that the PNG specification is pretty simple.

Using the Code

First create a new instance of APNG, then use the Load function to read the file, then you can loop through NumEmbeddedPNG, using the ToBitmap function to save each frame to a PNG file.

Here goes a sample code:

APNG png = new APNG();
for (int i = 0; i < png.NumEmbeddedPNG; i++)
    Bitmap image = png.ToBitmap(i);
    image.Save("frame" + i + ".png", ImageFormat.Png);

or with indexer:

APNG png = new APNG();
for (int i = 0; i < png.NumEmbeddedPNG; i++)
    png[i].Save("frame" + i + ".png", ImageFormat.Png);

Besides returning a new Bitmap, the APNG provides a SaveFile that you could use to save the actual frame data (complete original PNG file data).

Points of Interest

Because I suffered a lot while finding such code, I contribute it here as others won't have to get crazy looking for it. If you have any comments or suggestions, please feel free to tell me, or just modify the code yourself.


  • Version 1.0 - 2009-5-5 First release
  • Version 1.1 - 2009-5-6 Added indexer, more detailed introduction


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Authors

Software Developer (Senior) Bally Technologies
United States United States
I've been software developer since early 1991. My focuses have ranged from deeply embedded (Intel and ARM architectures,) to firmware (C and C++), to application level software under Linux and Windows (C, C++ and C#.) Applications developed with .NET under Windows have been primarily test and support applications for other development activities.

Huisheng Chen
Technical Lead
Australia Australia
I was born in the south of China, started to write GWBASIC code since 1993 when I was 13 years old, with professional .net(c#) and vb, founder of

Now I am living in Sydney, Australia.

You may also be interested in...

Comments and Discussions

QuestionAn updated code for this article Pin
amemiyasss23-Jul-12 21:18
memberamemiyasss23-Jul-12 21:18 
AnswerRe: An updated code for this article Pin
Huisheng Chen24-Jul-12 20:16
memberHuisheng Chen24-Jul-12 20:16 
QuestionExtend Bitmap to display one frame at a time? Pin
divStar26-Nov-10 9:14
memberdivStar26-Nov-10 9:14 
AnswerRe: Extend Bitmap to display one frame at a time? Pin
Unruled Boy28-Jan-11 20:55
memberUnruled Boy28-Jan-11 20:55 
Generalblend_op are not supported :( Pin
eviral16-Oct-10 12:00
membereviral16-Oct-10 12:00 
GeneralMy vote of 1 Pin
abcd1234f10-Aug-09 9:38
memberabcd1234f10-Aug-09 9:38 
GeneralRe: My vote of 1 Pin
Smart K84-Dec-09 11:17
memberSmart K84-Dec-09 11:17 
GeneralJust.... awesome!! Pin
APBilbo30-Jun-09 12:44
memberAPBilbo30-Jun-09 12:44 
GeneralRe: Just.... awesome!! Pin
Unruled Boy30-Jun-09 18:35
memberUnruled Boy30-Jun-09 18:35 
GeneralGreat Job~~~ Pin
pen_lake10-May-09 6:16
memberpen_lake10-May-09 6:16 
GeneralRe: Great Job~~~ Pin
Unruled Boy10-May-09 20:03
memberUnruled Boy10-May-09 20:03 
GeneralSuggestion Pin
harold aptroot5-May-09 8:40
memberharold aptroot5-May-09 8:40 
GeneralRe: Suggestion Pin
Unruled Boy5-May-09 16:42
memberUnruled Boy5-May-09 16:42 
Generalplease comment Pin
Unruled Boy4-May-09 21:09
memberUnruled Boy4-May-09 21:09 
GeneralRe: please comment Pin
nicholas_pei6-May-09 3:46
membernicholas_pei6-May-09 3:46 
GeneralRe: please comment Pin
Unruled Boy6-May-09 4:58
memberUnruled Boy6-May-09 4:58 
Generalrecompile images? Pin
agent_zer024-Oct-09 16:33
memberagent_zer024-Oct-09 16:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151126.1 | Last Updated 6 May 2009
Article Copyright 2009 by SprinterDave, Huisheng Chen
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid