合成GIF
/* 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 );
}
分解GIF
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
Image imgGif = Image.FromFile(@"d:\test.gif");
//Create a new FrameDimension object from this image
FrameDimension ImgFrmDim = new FrameDimension( imgGif.FrameDimensionsList[0] );
//Determine the number of frames in the image
//Note that all images contain at least 1 frame,
//but an animated GIF will contain more than 1 frame.
int nFrameCount = imgGif.GetFrameCount( ImgFrmDim );
// Save every frame into jpeg format
for( int i = 0; i < nFrameCount; i++ )
{
imgGif.SelectActiveFrame( ImgFrmDim, i );
imgGif.Save( string.Format( @"d:\Frame{0}.jpg", i ), ImageFormat.Jpeg );
}
搞定