C#能够处理gif图片?
能的话,C#处理gif图片的方法?

解决方案 »

  1.   

    对一般的GIF处理可是直接保存成256色的GIF如果需要透明可以参考http://blog.csdn.net/zgke/archive/2008/11/28/3401077.aspx
      

  2.   

    方法一(简单):用label,然后设置为背景图片
    方法二:使用GDI+ 来实现 (很粗略的实现,没有帧间隔)            Image image = Image.FromFile("e:\\temp.gif");
                
                FrameDimension fd = new FrameDimension(image.FrameDimensionsList[0]);
                int count = image.GetFrameCount(fd);
                Graphics g = this.panel1.CreateGraphics();
                while (true)
                {
                    
                    for (int i = 0; i < count; i++)
                    {
                        
                        //g.Clear(Color.White);
                        image.SelectActiveFrame(fd, i);
                        g.DrawImage(image, new Point(0, 0));
                        System.Threading.Thread.Sleep(100);
                        Application.DoEvents();
                    }
                }
    方法三:(推荐,有桢间隔)            Bitmap animatedGif = new Bitmap("e:\\temp2.gif");
                Graphics g = this.panel1.CreateGraphics();
                // A Gif image's frame delays are contained in a byte array 
                // in the image's PropertyTagFrameDelay Property Item's 
                // value property. 
                // Retrieve the byte array... 
                int PropertyTagFrameDelay = 0x5100;
                PropertyItem propItem = animatedGif.GetPropertyItem(PropertyTagFrameDelay);
                byte[] bytes = propItem.Value;            // Get the frame count for the Gif... 
                FrameDimension frameDimension = new FrameDimension(animatedGif.FrameDimensionsList[0]);
                int frameCount = animatedGif.GetFrameCount(FrameDimension.Time);            // Create an array of integers to contain the delays, 
                // in hundredths of a second, between each frame in the Gif image. 
                int[] delays = new int[frameCount + 1];
                int i = 0;
                for (i = 0; i <= frameCount - 1; i++)
                {
                    delays[i] = BitConverter.ToInt32(bytes, i * 4);
                }            // Play the Gif one time... 
                while (true)
                {
                    for (i = 0; i <= animatedGif.GetFrameCount(frameDimension) - 1; i++)
                    {
                        animatedGif.SelectActiveFrame(frameDimension, i);
                        g.DrawImage(animatedGif, new Point(0, 0));
                        Application.DoEvents();
                        Thread.Sleep(delays[i] * 10);
                    }
                }
      

  3.   

    参考
    http://www.cnblogs.com/KissKnife/archive/2008/11/12/923352.html
    http://www.cnblogs.com/mbskys/articles/714648.html