.net上操作gif图片
因为.NET Framework 上不能创建GIF图片, 因此 NGif 提供了一种在.NET Framework 上创建GIF图片的方法. NGif 能够把多张图片创建成动态的GIF图片,并且可以从GIF图片中提取出静态的图片. NGif 在codeproject上,地址:http://www.codeproject.com/KB/GDI-plus/NGif.aspx。
示例代码:
/* 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 );
}
还有java上的应用:http://www.fmsware.com/stuff/gif.html ,java的还有psd的读取实现。
浙公网安备 33010602011771号