NGif,用于.NET的动画GIF编码器

目录

介绍

使用代码

兴趣点


介绍

由于.NET Framework无法创建动画GIF图像,因此NGif提供了一种在.NET Framework中创建GIF动画的方法。它可以从多个图像创建动画GIF,并从动画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 );
}

兴趣点

在编写固定字节结构的二进制文件时,使用Stream替换BinaryWriter

https://www.codeproject.com/Articles/11505/NGif-Animated-GIF-Encoder-for-NET