转 把GIF图片转换成单个连续的图片 转 tif 等任意多帧图片转换bmp 或者gif等格式

转 把GIF图片转换成单个连续的图片

转 tif 等任意多帧图片转换bmp 或者gif等格式

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Desktop
{
    class ImageUtils
    {
        public static List<Bitmap> GifToBitmap(Image image)
        {
            if (image == null)
                return null;
            List<Bitmap> imgs = new List<Bitmap>();

            //获取tif图片的第一维           
            System.Drawing.Imaging.FrameDimension objDimension = new System.Drawing.Imaging.FrameDimension(image.FrameDimensionsList[0]);
            //遍历第一维所有帧数            
            int pageNumber = image.GetFrameCount(objDimension);
            for (int i = 0; i < pageNumber; i++)
            {
                //选定第i帧             
                image.SelectActiveFrame(objDimension, i);
                //取得图片大小                      
                System.Drawing.Size size = new System.Drawing.Size(image.Width, image.Height);
                //新建一个bmp图片                   
                System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(size.Width, size.Height);
                //新建一个画板                  
                System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
                //设置高质量插值法                  
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
                //设置高质量,低速度呈现平滑程度                   
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                //清空一下画布                     
                g.Clear(System.Drawing.Color.White);
                //在指定位置画图              
                g.DrawImage((Image)image, new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), new System.Drawing.Rectangle(0, 0, image.Width, image.Height), System.Drawing.GraphicsUnit.Pixel);
                //翻转图片               
                //bitmap.RotateFlip(RotateFlipType.Rotate270FlipXY);        
                //调整亮度
                //将每帧保存到imag图片里面            
                //bitmap.Save("1.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
                //释放临时图片资源
                g.Dispose();

                imgs.Add(bitmap);
            }
            return imgs;
        }
    }
}

你可能感兴趣的:(转 把GIF图片转换成单个连续的图片 转 tif 等任意多帧图片转换bmp 或者gif等格式)