Click here to Skip to main content
6,822,123 members and growing! (17,670 online)
Email Password   helpLost your password?
Multimedia » GDI+ » General     Intermediate License: The Code Project Open License (CPOL)

NGif, Animated GIF Encoder for .NET

By gOODiDEA.NET

Create animated GIF images using C#.
C#, VC7.1, .NETCF, Mobile, .NET1.1, Win2K, WinXP, Win2003, GDI+, VS.NET2003, Dev
Posted:1 Sep 2005
Views:121,824
Bookmarked:54 times
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
35 votes for this article.
Popularity: 5.80 Rating: 3.75 out of 5
4 votes, 11.4%
1
2 votes, 5.7%
2
1 vote, 2.9%
3
3 votes, 8.6%
4
25 votes, 71.4%
5

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


Member

Location: China China

Other popular GDI+ articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 73 (Total in Forum: 73) (Refresh)FirstPrevNext
GeneralBug involving the first frame PinmemberDataflashsabot3:56 23 Jan '10  
GeneralI've released a derived work Pinmembersbridewell11:44 24 Oct '09  
GeneralRe: I've released a derived work Pinmemberjambonbill16:39 3 Nov '09  
General"The process cannot access the file xpto because it is being used by another process". Pinmemberchico@dsi0:52 30 Sep '09  
QuestionCan I release a derived work please? Pinmembersbridewell10:12 4 Sep '09  
AnswerRe: Can I release a derived work please? Pinmemberjambonbill4:04 6 Oct '09  
GeneralRe: Can I release a derived work please? Pinmembersbridewell11:54 6 Oct '09  
GeneralRe: Can I release a derived work please? Pinmemberjambonbill15:50 6 Oct '09  
GeneralRe: Can I release a derived work please? [modified] Pinmembersbridewell10:10 7 Oct '09  
GeneralResize an animated gif background transparency Pinmembervuivuivui22:23 26 Aug '09  
Generalhow to force no transparency PinmemberAreJay8:55 20 Aug '09  
Generalit can't store more than 19 frames. Pinmemberinamgul2:00 26 Feb '09  
GeneralAnimated gif Timeline Properties PinmemberDaffy10123:01 2 Nov '08  
Generalan better implement PinmembergOODiDEA.NET15:54 13 Oct '08  
GeneralRe: an better implement Pinmemberecjob5:24 21 Oct '08  
GeneralRe: an better implement PinmemberSpirch15:13 2 Jan '09  
GeneralRe: an better implement PinmemberCeyhun7:20 25 Jul '09  
General怎样才能把体积减少一些啊?? Pinmemberecjob9:31 11 Oct '08  
General一处bug Pinmemberinteriv@qq.com18:05 6 Sep '08  
GeneralExporting frames [modified] Pinmemberjambonbill21:01 17 Aug '08  
GeneralPerformance improvement PinmemberMember 21880511:00 7 Aug '08  
GeneralRe: Performance improvement Pinmemberjambonbill1:30 14 Aug '08  
GeneralBugfix NextPixel() PinmemberMember 21880510:49 7 Aug '08  
GeneralRe: Bugfix NextPixel() PinmemberPaulNeyman2:08 11 Jan '10  
GeneralExcellent work! PinmemberDigiOz Multimedia19:47 18 Jun '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.

PermaLink | Privacy | Terms of Use
Last Updated: 1 Sep 2005
Editor: Smitha Vijayan
Copyright 2005 by gOODiDEA.NET
Everything else Copyright © CodeProject, 1999-2010
Web20 | Advertise on the Code Project