AnimatedGifEncoder.cs GifDecoder.cs

来源:互联网 发布:网络平台贷款是否合法 编辑:程序博客网 时间:2024/04/30 12:29
 用CF1真可怜,想要用bitmap.Save()把bitmap保存为gif格式都不让,还要用自己写的编码来实现,还好最近有了新发现,在网上找到一个比较好用的gif编码,解码C#封装类库,它由4个文件AnimatedGifEncoder.cs  GifDecoder.cs LZWEncoder.cs  NeuQuant.cs 组成.

加到工程里面,就可以象下面这样使用了,有兴趣可以试试.

使用例子:
  /* 合成 Gif */
  String [] imageFilePaths = new String[]{"d://Frame0.jpg","d://Frame1.jpg","d://Frame2.jpg"};

  string outputFilePath = "c://test.gif";

  AnimatedGifEncoder e = new AnimatedGifEncoder();

  e.Start( outputFilePath );
  //图片转换时间
  e.SetDelay(50);
  //1表示只动一次,0:表示循环,n:表示循环n次
  e.SetRepeat(0);

  for (int i = 0, count = imageFilePaths.Length; i < count; i++ )
  {
    e.AddFrame( Image.FromFile( imageFilePaths[i] ) );
    //或者e.AddFrame(Bitmap对象);
  }
  e.Finish();

   /* 分解 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 );  // 第i帧
    frame.Save( "......//image.png",ImageFormat.Png );
   } 
原创粉丝点击