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

AnswerRe: The gif be changed bigger? Pin
Shobin Mathew9-Jul-08 18:45
memberShobin Mathew9-Jul-08 18:45 
Generalits important [modified] Pin
ganesh154-Nov-07 20:18
memberganesh154-Nov-07 20:18 
GeneralRe: its important Pin
Shobin Mathew9-Jul-08 18:41
memberShobin Mathew9-Jul-08 18:41 
GeneralBug fixed Pin
chuanchu13-Aug-07 15:23
memberchuanchu13-Aug-07 15:23 
GeneralRe: Bug fixed Pin
Adnan8365-Oct-07 0:34
memberAdnan8365-Oct-07 0:34 
GeneralRe: Bug fixed Pin
cmhienng27-Nov-07 21:33
membercmhienng27-Nov-07 21:33 
GeneralRe: Bug fixed Pin
xzhang19-Mar-09 8:11
memberxzhang19-Mar-09 8:11 
GeneralTransparency Not Working Pin
Jim Hunt15-Jun-07 8:21
memberJim Hunt15-Jun-07 8:21 
I've tried settign a value for the transparency but no matter what I do it doesn't work. I noticed that the FindClosest function called in Save() was beign called before the Analyze function. I updated the code so that FindClosest now returns what looks like an accurate index as far as I can tell but when I look at th eGif in IE then the transparency is not showing (excuse the 'pun') and in a Gif editor the transparency is not set.

Has anyone else tried using the transparency in this? I really want to avoid sitting down and reading the enitre Gif Spec to understand this!

Thanks in advance

GeneralRe: Transparency Not Working Pin
chuanchu13-Aug-07 15:10
memberchuanchu13-Aug-07 15:10 
GeneralRe: Transparency Not Working Pin
Adnan8365-Oct-07 1:28
memberAdnan8365-Oct-07 1:28 
GeneralRe: Transparency Not Working Pin
xftan20-Oct-07 10:38
memberxftan20-Oct-07 10:38 
GeneralRe: Transparency Not Working Pin
Shobin Mathew10-Jul-08 3:06
memberShobin Mathew10-Jul-08 3:06 
GeneralRe: Transparency Not Working Pin
Equinox SE30 Jota26-Oct-11 15:24
memberEquinox SE30 Jota26-Oct-11 15:24 
GeneralRe: Transparency Not Working Pin
Chase Viking4-Jun-13 5:01
memberChase Viking4-Jun-13 5:01 
GeneralRe: Transparency Not Working Pin
Member 946120618-Sep-13 0:25
memberMember 946120618-Sep-13 0:25 
GeneralBug? Net CF Pin
Hoar Wu31-May-07 15:55
memberHoar Wu31-May-07 15:55 
GeneralRe: Bug? Net CF Pin
chuanchu13-Aug-07 15:12
memberchuanchu13-Aug-07 15:12 
GeneralRe: Bug? Net CF Pin
nixkuroi7-Jun-14 14:44
membernixkuroi7-Jun-14 14:44 
QuestionHas anybody been able to optimize this code? Pin
SubodhShakya23-Apr-07 20:50
memberSubodhShakya23-Apr-07 20:50 
AnswerRe: Has anybody been able to optimize this code? Pin
Ephoy9-May-07 1:29
memberEphoy9-May-07 1:29 
GeneralRe: Has anybody been able to optimize this code? Pin
kitkatrobins24-Sep-07 3:32
memberkitkatrobins24-Sep-07 3:32 
QuestionRe: Has anybody been able to optimize this code? Pin
Ephoy14-Oct-07 7:22
memberEphoy14-Oct-07 7:22 
AnswerRe: Has anybody been able to optimize this code? Pin
kitkatrobins14-Oct-07 23:04
memberkitkatrobins14-Oct-07 23:04 
GeneralRe: Has anybody been able to optimize this code? Pin
TODarkone18-Nov-07 9:15
memberTODarkone18-Nov-07 9:15 
QuestionPlay a gif in a Form? Pin
anderslundsgard22-Mar-07 21:41
memberanderslundsgard22-Mar-07 21:41 

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