Visual C++ 7.1.NET 1.1Windows 2000Windows XPWindows 2003Visual Studio .NET 2003C++C#Windows.NET CF.NETVisual StudioMobile AppsGDI+DevIntermediate
NGif, Animated GIF Encoder for .NET






4.02/5 (58 votes)
Create animated GIF images using C#.
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.