Click here to Skip to main content
13,295,643 members (33,014 online)
Click here to Skip to main content
Add your own
alternative version


116 bookmarked
Posted 1 Sep 2005

NGif, Animated GIF Encoder for .NET

, 1 Sep 2005
Rate this:
Please Sign up or sign in to vote.
Create animated GIF images using C#.

Sample Image - NGif.gif


Because .NET Framework can't create animated GIF images, NGif provides a way to create GIF animations in the .NET framework. It can create an animated GIF from several images and extract images from an animated GIF.

Using the code

/* create Gif */
//you should replace filepath
String [] imageFilePaths = new String[]{"c:\\01.png","c:\\02.png","c:\\03.png"}; 
String outputFilePath = "c:\\test.gif";
AnimatedGifEncoder e = new AnimatedGifEncoder();
e.Start( outputFilePath );
//-1:no repeat,0:always repeat
for (int i = 0, count = imageFilePaths.Length; i < count; i++ ) 
 e.AddFrame( Image.FromFile( imageFilePaths[i] ) );
/* extract Gif */
string outputPath = "c:\\";
GifDecoder gifDecoder = new GifDecoder();
gifDecoder.Read( "c:\\test.gif" );
for ( int i = 0, count = gifDecoder.GetFrameCount(); i < count; i++ ) 
 Image frame = gifDecoder.GetFrame( i ); // frame i
 frame.Save( outputPath + Guid.NewGuid().ToString() 
                       + ".png", ImageFormat.Png );

Points of Interest

Use Stream to replace BinaryWriter when you write a fixed-byte structured binary file.


  • 31 Aug 2005: Draft.


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


About the Author

China China
No Biography provided

You may also be interested in...


Comments and Discussions

AnswerRe: System.Windows.Media.Imaging.GifBitmapEncoder Pin
Member 1029123023-Sep-13 1:31
memberMember 1029123023-Sep-13 1:31 
QuestionNot properly disposing/closing images Pin
rdavidson228-Jul-12 12:26
memberrdavidson228-Jul-12 12:26 
QuestionThank you Pin
Member 835751315-Jun-12 17:30
memberMember 835751315-Jun-12 17:30 
QuestionBugfixed version Pin
avianbc11-Jun-12 15:22
memberavianbc11-Jun-12 15:22 
Fixed transparency, added stream support, and fixed invalid color on last 2 pixel bugs. Posted the archive on my website:

modified 4-May-15 9:34am.

AnswerRe: Bugfixed version Pin
class_Volrath28-Jun-14 13:19
memberclass_Volrath28-Jun-14 13:19 
AnswerRe: Bugfixed version Pin
horsedrowner30-Jun-14 8:13
memberhorsedrowner30-Jun-14 8:13 
GeneralMy vote of 5 Pin
manoj kumar choubey4-Mar-12 20:47
membermanoj kumar choubey4-Mar-12 20:47 
Bug[Bug] Last two pixels of every frame is wrong. Pin
codipro7-Jan-12 3:14
membercodipro7-Jan-12 3:14 
GeneralRe: [Bug] Last two pixels of every frame is wrong. Pin
morhost28-Feb-12 5:51
membermorhost28-Feb-12 5:51 
GeneralRe: [Bug] Last two pixels of every frame is wrong. Pin
Member 1034753121-Oct-13 9:23
memberMember 1034753121-Oct-13 9:23 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 1 Sep 2005
Article Copyright 2005 by gOODiDEA.NET
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid