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

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

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)

About the Author

gOODiDEA.NET

China China
No Biography provided

Comments and Discussions

 
QuestionGreat tool, saved me a lot of work! Pinmembermingonn29-Jan-14 13:58 
GeneralGreate Job :) PinmemberVinaymm12-Dec-13 0:51 
Questionsize limit? PinmemberMember 39966278-Nov-13 9:47 
AnswerRe: size limit? PinmemberNicke Da Silva Manarin21-Feb-14 11:43 
AnswerRe: size limit? PinmemberMember 106623506-Jun-14 9:42 
QuestionFileStream vs Stream PinmemberMember 1033860916-Oct-13 6:32 
AnswerRe: FileStream vs Stream PinmemberNicke Da Silva Manarin22-Oct-13 8:01 
QuestionCode Improvement [modified] PinmemberNicke Da Silva Manarin12-Oct-13 9:19 
QuestionI get black backgrounds. Has anyone ever come up with a solution for this? PinmemberMember 946120617-Sep-13 20:39 
SuggestionDelay method PinmemberSylvainguer17-Jul-13 21:58 
QuestionHow do i add this to my project? Pinmemberdroidap24-May-13 8:16 
AnswerRe: How do i add this to my project? PinmemberMember 1029123023-Sep-13 0:33 
QuestionI created a new dll file which is a wrapper from c++ of a gif animation if you want Pinmemberchocolade18-May-13 4:32 
QuestionSystem.Windows.Media.Imaging.GifBitmapEncoder PinmemberPie At The Raven16-May-13 12:14 
AnswerRe: System.Windows.Media.Imaging.GifBitmapEncoder PinmemberMember 1029123023-Sep-13 0:31 
QuestionNot properly disposing/closing images Pinmemberrdavidson228-Jul-12 11:26 
What is the propery way to dispose/close the images that are added as frames? It doesnt seem to be releasing some of them.
QuestionThank you PinmemberMember 835751315-Jun-12 16:30 
QuestionBugfixed version Pinmemberavianbc11-Jun-12 14:22 
AnswerRe: Bugfixed version Pinmemberclass_Volrath28-Jun-14 12:19 
AnswerRe: Bugfixed version Pinmemberhorsedrowner30-Jun-14 7:13 
GeneralMy vote of 5 Pinmembermanoj kumar choubey4-Mar-12 19:47 
Bug[Bug] Last two pixels of every frame is wrong. Pinmembercodipro7-Jan-12 2:14 
GeneralRe: [Bug] Last two pixels of every frame is wrong. Pinmembermorhost28-Feb-12 4:51 
GeneralRe: [Bug] Last two pixels of every frame is wrong. PinmemberMember 1034753121-Oct-13 8:23 
GeneralTransperency PinmemberJeremiasK24-Feb-11 7:45 

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