5,316,172 members and growing! (18,404 online)
Email Password   helpLost your password?
Multimedia » GDI+ » General     Intermediate

NGif, Animated GIF Encoder for .NET

By gOODiDEA.NET

Create animated GIF images using C#.
C#, VC7.1, C++, .NET CF, Windows, .NET, .NET 1.1, Win2K, WinXP, Win2003, Mobile, GDI+, VS.NET2003, Visual Studio, Dev

Posted: 1 Sep 2005
Updated: 1 Sep 2005
Views: 64,872
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
26 votes for this Article.
Popularity: 5.16 Rating: 3.65 out of 5
3 votes, 11.5%
1
2 votes, 7.7%
2
0 votes, 0.0%
3
2 votes, 7.7%
4
19 votes, 73.1%
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

gOODiDEA.NET



Location: China China

Other popular GDI+ articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 48 (Total in Forum: 48) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralExcellent work!memberDigiOz Multimedia19:47 18 Jun '08  
GeneralThe gif be changed bigger?membertintown_liu15:35 25 Dec '07  
GeneralRe: The gif be changed bigger?memberShobin Mathew19:45 9 Jul '08  
Generalits important [modified]memberganesh1521:18 4 Nov '07  
GeneralRe: its importantmemberShobin Mathew19:41 9 Jul '08  
GeneralBug fixedmemberchuanchu16:23 13 Aug '07  
GeneralRe: Bug fixedmemberAdnan8361:34 5 Oct '07  
GeneralRe: Bug fixedmembercmhienng22:33 27 Nov '07  
GeneralTransparency Not WorkingmemberJim Hunt9:21 15 Jun '07  
GeneralRe: Transparency Not Workingmemberchuanchu16:10 13 Aug '07  
GeneralRe: Transparency Not Workingmemberzerodevice2:55 29 Aug '07  
GeneralRe: Transparency Not WorkingmemberAdnan8362:28 5 Oct '07  
GeneralRe: Transparency Not Workingmemberxftan11:38 20 Oct '07  
GeneralRe: Transparency Not WorkingmemberShobin Mathew4:06 10 Jul '08  
GeneralBug? Net CFmemberHoar Wu16:55 31 May '07  
GeneralRe: Bug? Net CFmemberchuanchu16:12 13 Aug '07  
GeneralHas anybody been able to optimize this code?memberSubodhShakya21:50 23 Apr '07  
AnswerRe: Has anybody been able to optimize this code?memberLothver2:29 9 May '07  
GeneralRe: Has anybody been able to optimize this code?memberkitkatrobins4:32 24 Sep '07  
QuestionRe: Has anybody been able to optimize this code?memberLothver8:22 14 Oct '07  
AnswerRe: Has anybody been able to optimize this code?memberkitkatrobins0:04 15 Oct '07  
GeneralRe: Has anybody been able to optimize this code?memberTODarkone10:15 18 Nov '07  
GeneralPlay a gif in a Form?memberd00_ape22:41 22 Mar '07  
GeneralRe: Play a gif in a Form?memberyuxuetaoxp4:21 8 Jan '08  
GeneralLZW Patent No. 4,558,302membereschneider10018:53 9 Mar '07  

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

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