Click here to Skip to main content
Click here to Skip to main content

NGif, Animated GIF Encoder for .NET

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

Sample Image - NGif.gif

Introduction

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 );
e.SetDelay(500);
//-1:no repeat,0:always repeat
e.SetRepeat(0);
for (int i = 0, count = imageFilePaths.Length; i < count; i++ ) 
{
 e.AddFrame( Image.FromFile( imageFilePaths[i] ) );
}
e.Finish();
/* 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.

History

  • 31 Aug 2005: Draft.

License

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

Share

About the Author

gOODiDEA.NET

China China
No Biography provided

Comments and Discussions

 
SuggestionDelay method PinmemberSylvainguer17-Jul-13 22:58 
QuestionHow do i add this to my project? Pinmemberdroidap24-May-13 9:16 
AnswerRe: How do i add this to my project? PinmemberMember 1029123023-Sep-13 1:33 
QuestionI created a new dll file which is a wrapper from c++ of a gif animation if you want Pinmemberchocolade18-May-13 5:32 
QuestionSystem.Windows.Media.Imaging.GifBitmapEncoder PinmemberPie At The Raven16-May-13 13:14 
AnswerRe: System.Windows.Media.Imaging.GifBitmapEncoder PinmemberMember 1029123023-Sep-13 1:31 
QuestionNot properly disposing/closing images Pinmemberrdavidson228-Jul-12 12:26 
QuestionThank you PinmemberMember 835751315-Jun-12 17:30 
QuestionBugfixed version Pinmemberavianbc11-Jun-12 15:22 
AnswerRe: Bugfixed version Pinmemberclass_Volrath28-Jun-14 13:19 
AnswerRe: Bugfixed version Pinmemberhorsedrowner30-Jun-14 8:13 
GeneralMy vote of 5 Pinmembermanoj kumar choubey4-Mar-12 20:47 
Bug[Bug] Last two pixels of every frame is wrong. Pinmembercodipro7-Jan-12 3:14 
GeneralRe: [Bug] Last two pixels of every frame is wrong. Pinmembermorhost28-Feb-12 5:51 
GeneralRe: [Bug] Last two pixels of every frame is wrong. PinmemberMember 1034753121-Oct-13 9:23 
GeneralTransperency PinmemberJeremiasK24-Feb-11 8:45 
GeneralRe: Transperency Pinmemberv2leon28-Aug-11 23:49 
GeneralRe: Transperency Pinmembermaoshu22-Dec-12 1:14 
GeneralRe: Transperency PinmemberFroogabadoodle4-Jun-13 5:48 
QuestionSecurity Warning [modified] Pinmemberjedi-samurai18-Dec-10 22:53 
AnswerRe: Security Warning [modified] PinmemberJajnick1-Sep-12 6:14 
GeneralLZWEncoder Pinmembertom roarty12-Dec-10 5:59 
QuestionGifDecoder.cs exceptions PinmemberDivya Muppa29-Sep-10 11:16 
GeneralTransparency Pinmembergameguy2716-Aug-10 7:39 
GeneralBug involving the first frame PinmemberDataflashsabot23-Jan-10 3:56 
GeneralI've released a derived work Pinmembersbridewell24-Oct-09 11:44 
GeneralRe: I've released a derived work Pinmemberjambonbill3-Nov-09 16:39 
General"The process cannot access the file xpto because it is being used by another process". Pinmemberchico@dsi30-Sep-09 0:52 
GeneralRe: "The process cannot access the file xpto because it is being used by another process". PinmemberRassler481-Mar-13 2:16 
QuestionCan I release a derived work please? Pinmembersbridewell4-Sep-09 10:12 
AnswerRe: Can I release a derived work please? Pinmemberjambonbill6-Oct-09 4:04 
GeneralRe: Can I release a derived work please? Pinmembersbridewell6-Oct-09 11:54 
GeneralRe: Can I release a derived work please? Pinmemberjambonbill6-Oct-09 15:50 
GeneralRe: Can I release a derived work please? [modified] Pinmembersbridewell7-Oct-09 10:10 
GeneralResize an animated gif background transparency Pinmembervuivuivui26-Aug-09 22:23 
Questionhow to force no transparency PinmemberAreJay20-Aug-09 8:55 
Generalit can't store more than 19 frames. Pinmemberinamgul26-Feb-09 2:00 
GeneralAnimated gif Timeline Properties PinmemberDaffy1012-Nov-08 23:01 
Generalan better implement PinmembergOODiDEA.NET13-Oct-08 15:54 
GeneralRe: an better implement Pinmemberecjob21-Oct-08 5:24 
GeneralRe: an better implement PinmemberSpirch2-Jan-09 15:13 
GeneralRe: an better implement PinmemberCeyhun25-Jul-09 7:20 
GeneralRe: an better implement PinmemberNathanael Jones5-Jan-12 7:33 
Question怎样才能把体积减少一些啊?? Pinmemberecjob11-Oct-08 9:31 
General一处bug Pinmemberinteriv@qq.com6-Sep-08 18:05 
GeneralExporting frames [modified] Pinmemberjambonbill17-Aug-08 21:01 
GeneralPerformance improvement PinmemberMember 21880517-Aug-08 1:00 
GeneralRe: Performance improvement Pinmemberjambonbill14-Aug-08 1:30 
GeneralBugfix NextPixel() PinmemberMember 21880517-Aug-08 0:49 
GeneralRe: Bugfix NextPixel() PinmemberPaulNeyman11-Jan-10 2:08 

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