Tag:开源 , 源码 , 控件 , 控件开发 , 皮肤 , Skin , Web Service , AJAX , JQuery , Flex , Silverlight , Javascript , CSS , SQL , 网站开发 , 数据库 , 合成与分解GIF图片

 
您的位置: >> 首页 >> .Net视角 >> 合成与分解GIF图片

合成与分解GIF图片

2010-05-24  来自:CodeProject  字体大小:【  
  • 摘要:.NET Framework 中不能创建动态GIF图片,本文所提供NGif 组件为大家提供了一种合成GIF动态图片,以及将动态图片分解成单张静态图片的方法

.NET Framework 中不能创建动态GIF图片,本文所提供NGif 组件为大家提供了一种合成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 );
}



注意:在你写一个 fixed-byte 结构文件时,使用 Stream 替换 BinaryWriter 。

本文的源码及示例请到源码下载页进行下载

作者:gOODiDEA.NET

相关文章: