zoukankan      html  css  js  c++  java
  • 动态GIF图片处理

    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Drawing.Imaging;
     
    public class ImageHelper
    {
        /// <summary>
        
    /// 获取图片中的各帧
        
    /// </summary>
        
    /// <param name="pPath">图片路径</param>
        
    /// <param name="pSavePath">保存路径</param>
        public void GetFrames(string pPath, string pSavedPath)
        {
            Image gif = Image.FromFile(pPath);
            FrameDimension fd = new FrameDimension(gif.FrameDimensionsList[0]);
            
            //获取帧数(gif图片可能包含多帧,其它格式图片一般仅一帧)
            int count = gif.GetFrameCount(fd);
            
            //以Jpeg格式保存各帧
            for (int i = 0; i < count; i++)
            {
                gif.SelectActiveFrame(fd, i);
                gif.Save(pSavedPath + "\\frame_" + i + ".jpg", ImageFormat.Jpeg);
            }
        }
        //http://www.codeproject.com/KB/GDI-plus/NGif.aspx
        public bool CreateGifImage()
        {
            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 );
            }
        }
    }
  • 相关阅读:
    对 Spring IoC 的理解
    初识 Spring 框架
    CSS 全局样式
    Bootstrap 12 栅格系统
    551 闭包,浏览器垃圾回收机制/内存收机制
    550 JavaScript运行机制之“堆栈”
    549 数据类型转换汇总:转换为Number、字符串、布尔,比 较操作==、===,练习题
    547 Promise:Ajax 的串行、并行, Promise的executor和状态,then、catch、finally,then链
    546 变量提升
    545 parseInt解析
  • 原文地址:https://www.cnblogs.com/bober/p/2194108.html
Copyright © 2011-2022 走看看