首页 | IT新闻 | 硬件 | 操作系统 | 开发 | 网络编程 | 数据库 | 热门框架 | 网络安全 | 组网 | 建站指南 | 网页制作 | 特效 | 实用技巧 | 服务器 | 办公 | QQ | 探索 | 社区

  • 技术部落
  • 部落首页 > 程序开发 > C/C#/C++ > 正文
  • C#分解和合成Gif图像的方法
      2007-8-25  来源:CSDN  编辑:Jsbulo  热度:

      一个Gif图像文件,是有几个文件进行合成的,因此处理此类文件的时候,不能像Jpeg或者Bmp文件那样处理。需要把Gif文件拆分帧的形式,然后对每一帧进行处理,处理完后再合成Gif

    但是对于一个Gif进行拆分,其实Image对象本身就支持,例如对于一个Gif文件拆分成Jpeg文件方式,可以按照如下的方式进行处理。

        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 );

        }