如题

解决方案 »

  1.   

    ref:
    http://blog.csdn.net/knight94/archive/2006/07/03/871038.aspx
      

  2.   

    谢谢愚翁的链接,不过里面只有gif的分解.我的目的是把分解后的gif逐帧显示,gif每帧之间肯定有延时,而且是不一样的,这个延时如何获得呢?
      

  3.   

    自己解决了,gif文件本身存储有每帧的延时,可以利用PropertyItem取出来
      

  4.   

    如果仅仅是为了显示Gif,不需要这么复杂,直接用ImageAnimator就可以了。http://blog.csdn.net/Mittermeyer/archive/2006/08/28/1131535.aspx
      

  5.   

    public static void GetFrame(Image image, ref Image[] frames, ref Int32[] delay)
            {
                FrameDimension fd = new FrameDimension(image.FrameDimensionsList[0]);
                int count = image.GetFrameCount(fd);
                frames = new Image[count];
                delay = new Int32[count];
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                for (int i = 0; i < count; i++)
                {
                    image.SelectActiveFrame(fd, i);
                    image.Save(ms, ImageFormat.Png);
                    frames[i] = Image.FromStream(ms);
                }            PropertyItem pItem = null;            for (int i = 0; i < image.PropertyIdList.Length; i++)
                {
                    if ((int)image.PropertyIdList.GetValue(i) == 0x5100)
                    {
                        pItem = (PropertyItem)image.PropertyItems.GetValue(i);
                        break;
                    }
                }            byte[] delayByte = new byte[4];            if (pItem != null)
                {
                    for (int i = 0; i < count; i++)
                    {
                        //将字节数组转成整型,这里数组大小为4是因为c#里一个整型4字节长
                        delayByte[0] = pItem.Value[i * 4];
                        delayByte[1] = pItem.Value[1 + i * 4];
                        delayByte[2] = pItem.Value[2 + i * 4];
                        delayByte[3] = pItem.Value[3 + i * 4];
                        delay[i] = BitConverter.ToInt32(delayByte, 0);
                    }
                }
            }
    这是一个分解帧的方法,可以获得每一帧和每帧的延时.
    获得帧的是PropertyItem,这里的PropertyItem将存放延时数.
    图形文件有很多相关信息,如gif的延时,长度等等.这些数据都存放在image.PropertyItems集合里面,其中,只有image.PropertyId为0x5100才是存放延时的数据的.这些信息你可以上msdn上查到,英文的.另外取得的延时数组delay[]比实际的小10倍,即实际延时应该是delay[i]*10