Click here to Skip to main content
14,035,939 members
Click here to Skip to main content
Add your own
alternative version


117 bookmarked
Posted 1 Sep 2005
Licenced CPOL

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

QuestionSystem.Windows.Media.Imaging.GifBitmapEncoder Pin
Brian Herbert16-May-13 12:14
memberBrian Herbert16-May-13 12:14 
AnswerRe: System.Windows.Media.Imaging.GifBitmapEncoder Pin
Member 1029123023-Sep-13 0:31
memberMember 1029123023-Sep-13 0:31 
QuestionNot properly disposing/closing images Pin
rdavidson228-Jul-12 11:26
memberrdavidson228-Jul-12 11:26 
QuestionThank you Pin
Member 835751315-Jun-12 16:30
memberMember 835751315-Jun-12 16:30 
QuestionBugfixed version Pin
avianbc11-Jun-12 14:22
memberavianbc11-Jun-12 14:22 
AnswerRe: Bugfixed version Pin
class_Volrath28-Jun-14 12:19
memberclass_Volrath28-Jun-14 12:19 
AnswerRe: Bugfixed version Pin
Vivelin30-Jun-14 7:13
memberVivelin30-Jun-14 7:13 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey4-Mar-12 19:47
professionalManoj Kumar Choubey4-Mar-12 19:47 
Bug[Bug] Last two pixels of every frame is wrong. Pin
codipro7-Jan-12 2:14
membercodipro7-Jan-12 2:14 
GeneralRe: [Bug] Last two pixels of every frame is wrong. Pin
morhost28-Feb-12 4:51
membermorhost28-Feb-12 4:51 
GeneralRe: [Bug] Last two pixels of every frame is wrong. Pin
Member 1034753121-Oct-13 8:23
memberMember 1034753121-Oct-13 8:23 
GeneralTransperency Pin
JeremiasK24-Feb-11 7:45
memberJeremiasK24-Feb-11 7:45 
GeneralRe: Transperency Pin
v2leon28-Aug-11 22:49
memberv2leon28-Aug-11 22:49 
GeneralRe: Transperency Pin
maoshu22-Dec-12 0:14
membermaoshu22-Dec-12 0:14 
GeneralRe: Transperency Pin
Chase Viking4-Jun-13 4:48
memberChase Viking4-Jun-13 4:48 
QuestionSecurity Warning [modified] Pin
jedi-samurai18-Dec-10 21:53
memberjedi-samurai18-Dec-10 21:53 
AnswerRe: Security Warning [modified] Pin
Jajnick1-Sep-12 5:14
memberJajnick1-Sep-12 5:14 
GeneralLZWEncoder Pin
tom roarty12-Dec-10 4:59
membertom roarty12-Dec-10 4:59 
QuestionGifDecoder.cs exceptions Pin
Divya Muppa29-Sep-10 10:16
memberDivya Muppa29-Sep-10 10:16 
GeneralTransparency Pin
gameguy2716-Aug-10 6:39
membergameguy2716-Aug-10 6:39 
GeneralBug involving the first frame Pin
Dataflashsabot23-Jan-10 2:56
memberDataflashsabot23-Jan-10 2:56 
GeneralI've released a derived work Pin
sbridewell24-Oct-09 10:44
membersbridewell24-Oct-09 10:44 
GeneralRe: I've released a derived work Pin
jambonbill3-Nov-09 15:39
memberjambonbill3-Nov-09 15:39 
General"The process cannot access the file xpto because it is being used by another process". Pin
frantic029-Sep-09 23:52
professionalfrantic029-Sep-09 23:52 
GeneralRe: "The process cannot access the file xpto because it is being used by another process". Pin
Rassler481-Mar-13 1:16
memberRassler481-Mar-13 1:16 

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 | Cookies | Terms of Use | Mobile
Web05 | 2.8.190424.1 | Last Updated 1 Sep 2005
Article Copyright 2005 by gOODiDEA.NET
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid