Click here to Skip to main content
13,661,790 members
Click here to Skip to main content
Add your own
alternative version

Stats

1.2M views
15.7K downloads
116 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

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

You may also be interested in...

Pro
Pro

Comments and Discussions

 
GeneralRe: Can I release a derived work please? Pin
jambonbill6-Oct-09 14:50
memberjambonbill6-Oct-09 14:50 
GeneralRe: Can I release a derived work please? [modified] Pin
sbridewell7-Oct-09 9:10
membersbridewell7-Oct-09 9:10 
GeneralResize an animated gif background transparency Pin
vuivuivui26-Aug-09 21:23
membervuivuivui26-Aug-09 21:23 
Questionhow to force no transparency Pin
AreJay20-Aug-09 7:55
memberAreJay20-Aug-09 7:55 
Generalit can't store more than 19 frames. Pin
inamgul26-Feb-09 1:00
memberinamgul26-Feb-09 1:00 
GeneralAnimated gif Timeline Properties Pin
Daffy1012-Nov-08 22:01
memberDaffy1012-Nov-08 22:01 
Generalan better implement Pin
gOODiDEA.NET13-Oct-08 14:54
membergOODiDEA.NET13-Oct-08 14:54 
GeneralRe: an better implement Pin
ecjob21-Oct-08 4:24
memberecjob21-Oct-08 4:24 
GeneralRe: an better implement Pin
Spirch2-Jan-09 14:13
memberSpirch2-Jan-09 14:13 
GeneralRe: an better implement Pin
Ceyhun25-Jul-09 6:20
memberCeyhun25-Jul-09 6:20 
GeneralRe: an better implement Pin
Nathanael Jones5-Jan-12 6:33
memberNathanael Jones5-Jan-12 6:33 
Question怎样才能把体积减少一些啊?? Pin
ecjob11-Oct-08 8:31
memberecjob11-Oct-08 8:31 
General一处bug Pin
interiv@qq.com6-Sep-08 17:05
memberinteriv@qq.com6-Sep-08 17:05 
GeneralExporting frames [modified] Pin
jambonbill17-Aug-08 20:01
memberjambonbill17-Aug-08 20:01 
GeneralPerformance improvement Pin
Member 21880517-Aug-08 0:00
memberMember 21880517-Aug-08 0:00 
GeneralRe: Performance improvement Pin
jambonbill14-Aug-08 0:30
memberjambonbill14-Aug-08 0:30 
GeneralBugfix NextPixel() Pin
Member 21880516-Aug-08 23:49
memberMember 21880516-Aug-08 23:49 
GeneralRe: Bugfix NextPixel() Pin
PaulNeyman11-Jan-10 1:08
memberPaulNeyman11-Jan-10 1:08 
GeneralExcellent work! Pin
DigiOz Multimedia18-Jun-08 18:47
memberDigiOz Multimedia18-Jun-08 18:47 
QuestionThe gif be changed bigger? Pin
tintown_liu25-Dec-07 14:35
membertintown_liu25-Dec-07 14:35 
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 

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