Click here to Skip to main content
11,415,301 members (80,676 online)
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

 
GeneralRe: Transperency Pin
v2leon28-Aug-11 23:49
memberv2leon28-Aug-11 23:49 
GeneralRe: Transperency Pin
maoshu22-Dec-12 1:14
membermaoshu22-Dec-12 1:14 
GeneralRe: Transperency Pin
Froogabadoodle4-Jun-13 5:48
memberFroogabadoodle4-Jun-13 5:48 
QuestionSecurity Warning [modified] Pin
jedi-samurai18-Dec-10 22:53
memberjedi-samurai18-Dec-10 22:53 
Software i developed with this Gif.Components.dll is deleted by security soft (Norton 2010) warning with high level risk. There was no warning with other security soft (Mcafee).

Is anyone encountered with this kind of problem with this dll?

-----------------

There is no warning with Debug file, only Release file.

Visual Studio 2008
Windows7
modified on Monday, December 20, 2010 8:45 AM

AnswerRe: Security Warning [modified] Pin
Jajnick1-Sep-12 6:14
memberJajnick1-Sep-12 6:14 
GeneralLZWEncoder Pin
tom roarty12-Dec-10 5:59
membertom roarty12-Dec-10 5:59 
QuestionGifDecoder.cs exceptions Pin
Divya Muppa29-Sep-10 11:16
memberDivya Muppa29-Sep-10 11:16 
GeneralTransparency Pin
gameguy2716-Aug-10 7:39
membergameguy2716-Aug-10 7:39 
GeneralBug involving the first frame Pin
Dataflashsabot23-Jan-10 3:56
memberDataflashsabot23-Jan-10 3:56 
GeneralI've released a derived work Pin
sbridewell24-Oct-09 11:44
membersbridewell24-Oct-09 11:44 

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.150427.4 | Last Updated 1 Sep 2005
Article Copyright 2005 by gOODiDEA.NET
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid