Click here to Skip to main content
Click here to Skip to main content
Go to top

.NET MNG Viewer

, 9 Apr 2009
Rate this:
Please Sign up or sign in to vote.
A native .NET library and application to view the PNGs embedded in a MNG

Introduction

For the past few years, I've been searching for a .NET library that would load MNG (Multiple-image Network Graphics) animations and allow me to extract Bitmaps of the embedded images on a 'frame-by-frame' basis.  Ideally, I was looking for something that was native .NET.  Having failed to find a 100% native .NET solution, I decided to undertake a MNG library myself.

This article contains my initial work on such a library. It should be noted that the library contained within is NOT a 100% compatible MNG decoder per the MNG specification. My sole desire at this time was to extract embedded PNGs within a MNG. Therefore, no effort has been made to handle MNG Loops, Basis objects, Delta PNGs, Backgrounds, Frame definitions, or a whole host of other MNG 'chunks'.

Luckily, all the MNGs I deal with on a day-to-day basis are quite simple and this library fits my needs.

Background 

I won't go into much detail of what an MNG is or of the MNG file format. If you're interested in this article, then it's probably safe to say you're already somewhat knowledgeable in MNGs.

For much more detailed information, take a look at the following links:

Using the Code

The attached ZIP file contains a Visual Studio 2008 solution with two projects:

  1. MNG Viewer  - WinForms application to demonstrate the library capabilities
  2. SprinterMNG - The library responsible for reading MNGs

SprinterMNG contains one public class MNG.  It is through this class that MNGs are loaded.

Loading an MNG is as easy as:

MNG mng = new MNG();
mng.Load( filename );  

Extracting the PNGs embedded in the MNG is as easy as:

int numEmbeddedPNG = mng.NumEmbeddedPNG;
for( int i = 0; i < numEmbeddedPNG; i++ )
{
	Bitmap b = mng.ToBitmap(i);
} 

I've attempted to structure the SprinterMNG library such that the addition of MNG specification elements not covered in the initial version of the library would be as easy as possible.

Points of Interest

When I first decided to write this library, I was thinking that I would need to handle (parse, uncompress, render) the PNG image data myself. I got as far as implementing the decompression (using SharpZipLib) when I remembered that .NET natively supports loading of PNG file formats. Since each embedded PNG image within a MNG conforms to the PNG chunk specifications, I found that all I needed to do was pre-pend the PNG data extracted from the MNG with the PNG file signature to obtain a PNG formatted data stream. The resulting data stream (implemented as a MemoryStream object in the library) can be used to create a Bitmap as shown below. 

Bitmap b = (Bitmap)Bitmap.FromStream( pngs[index].ToStream() ); 

History 

  • April 9, 2009 - Initial revision of the library and sample application

License

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

Share

About the Author

SprinterDave
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.

Comments and Discussions

 
Generalmng creation Pinmemberjambonbill4-Nov-09 2:11 
GeneralRe: mng creation PinmemberSprinterDave8-Jan-10 6:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web01 | 2.8.140905.1 | Last Updated 9 Apr 2009
Article Copyright 2009 by SprinterDave
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid