Click here to Skip to main content
Click here to Skip to main content

NGif, Animated GIF Encoder for .NET

By , 1 Sep 2005
 

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
China China
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionI created a new dll file which is a wrapper from c++ of a gif animation if you wantmemberchocolade5hrs 50mins ago 
QuestionSystem.Windows.Media.Imaging.GifBitmapEncodermemberPie At The Raven16 May '13 - 12:14 
QuestionNot properly disposing/closing imagesmemberrdavidson228 Jul '12 - 11:26 
QuestionThank youmemberMember 835751315 Jun '12 - 16:30 
QuestionBugfixed versionmemberavianbc11 Jun '12 - 14:22 
GeneralMy vote of 5membermanoj kumar choubey4 Mar '12 - 19:47 
Bug[Bug] Last two pixels of every frame is wrong.membercodipro7 Jan '12 - 2:14 
GeneralRe: [Bug] Last two pixels of every frame is wrong.membermorhost28 Feb '12 - 4:51 
GeneralTransperencymemberJeremiasK24 Feb '11 - 7:45 
GeneralRe: Transperencymemberv2leon28 Aug '11 - 22:49 
GeneralRe: Transperencymembermaoshu22 Dec '12 - 0:14 
QuestionSecurity Warning [modified]memberjedi-samurai18 Dec '10 - 21:53 
AnswerRe: Security Warning [modified]memberJajnick1 Sep '12 - 5:14 
GeneralLZWEncodermembertom roarty12 Dec '10 - 4:59 
QuestionGifDecoder.cs exceptionsmemberDivya Muppa29 Sep '10 - 10:16 
GeneralTransparencymembergameguy2716 Aug '10 - 6:39 
GeneralBug involving the first framememberDataflashsabot23 Jan '10 - 2:56 
GeneralI've released a derived workmembersbridewell24 Oct '09 - 10:44 
GeneralRe: I've released a derived workmemberjambonbill3 Nov '09 - 15:39 
General"The process cannot access the file xpto because it is being used by another process".memberchico@dsi29 Sep '09 - 23:52 
GeneralRe: "The process cannot access the file xpto because it is being used by another process".memberRassler481 Mar '13 - 1:16 
QuestionCan I release a derived work please?membersbridewell4 Sep '09 - 9:12 
AnswerRe: Can I release a derived work please?memberjambonbill6 Oct '09 - 3:04 
GeneralRe: Can I release a derived work please?membersbridewell6 Oct '09 - 10:54 
GeneralRe: Can I release a derived work please?memberjambonbill6 Oct '09 - 14:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 1 Sep 2005
Article Copyright 2005 by gOODiDEA.NET
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid