您的位置:首页 > 编程语言 > C#

C# 获取GIF帧率-每张图像的时间间隔

2018-02-03 16:35 1021 查看
public int GetDelay(string sfile)

        {

            Image img = Image.FromFile("D:\\000.gif");//加载Gif图片

            FrameDimension dim = new FrameDimension(img.FrameDimensionsList[0]);

            int framcount = img.GetFrameCount(dim);

            if (framcount <= 1)

                return 0;

            else

            {

                int delay = 0;

                bool stop = false;

                for (int i = 0; i < framcount; i++)//遍历图像帧

                {

                    if (stop == true)

                        break;

                    img.SelectActiveFrame(dim, i);//激活当前帧

                    for (int j = 0; j < img.PropertyIdList.Length; j++)//遍历帧属性

                    {

                        if ((int)img.PropertyIdList.GetValue(j) == 0x5100)//如果是延迟时间

                        {

                            PropertyItem pItem = (PropertyItem)img.PropertyItems.GetValue(j);//获取延迟时间属性

                            byte[] delayByte = new byte[4];//延迟时间,以1/100秒为单位

                            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 = BitConverter.ToInt32(delayByte, 0) * 10; //乘以10,获取到毫秒

                            stop = true;

                            break;

                        }

                    }

                }

                return delay;

            }

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: