Click here to Skip to main content
14,032,941 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

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 
The GifComponents library, which is based on this library and is also released under the CPOL, is now available here (project web page)[^] or here (sourceforge main project page)[^]

Share and enjoy... I hope to see lots of new entries in the bug tracker Smile | :)

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 
QuestionCan I release a derived work please? Pin
sbridewell4-Sep-09 9:12
membersbridewell4-Sep-09 9:12 
AnswerRe: Can I release a derived work please? Pin
jambonbill6-Oct-09 3:04
memberjambonbill6-Oct-09 3:04 
GeneralRe: Can I release a derived work please? Pin
sbridewell6-Oct-09 10:54
membersbridewell6-Oct-09 10:54 
GeneralRe: Can I release a derived work please? Pin
jambonbill6-Oct-09 14:50
memberjambonbill6-Oct-09 14:50 
GeneralRe: Can I release a derived work please? [modified] Pin
sbridewell7-Oct-09 9:10
membersbridewell7-Oct-09 9:10 
GeneralResize an animated gif background transparency Pin
vuivuivui26-Aug-09 21:23
membervuivuivui26-Aug-09 21:23 
Questionhow to force no transparency Pin
Are Jay20-Aug-09 7:55
memberAre Jay20-Aug-09 7:55 
Generalit can't store more than 19 frames. Pin
inamgul26-Feb-09 1:00
memberinamgul26-Feb-09 1:00 
GeneralAnimated gif Timeline Properties Pin
Daffy1012-Nov-08 22:01
memberDaffy1012-Nov-08 22:01 
Generalan better implement Pin
gOODiDEA.NET13-Oct-08 14:54
membergOODiDEA.NET13-Oct-08 14:54 
GeneralRe: an better implement Pin
ecjob21-Oct-08 4:24
memberecjob21-Oct-08 4:24 
GeneralRe: an better implement Pin
Spirch2-Jan-09 14:13
memberSpirch2-Jan-09 14:13 
GeneralRe: an better implement Pin
Ceyhun25-Jul-09 6:20
memberCeyhun25-Jul-09 6:20 
GeneralRe: an better implement Pin
Nathanael Jones5-Jan-12 6:33
memberNathanael Jones5-Jan-12 6: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.

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