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;
}
}
{
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;
}
}
相关文章推荐
- C#获取Gif图片每一帧的时间
- [C#] 获取两个时间点的时间间隔
- C# 时间相减的计算方法(获取时间间隔)
- C# 时间相减的计算方法(获取时间间隔)
- C# 时间相减的计算方法(获取时间间隔)
- 23.获取两个时间的自然天数间隔
- C# 计算日期时间的间隔天数
- C# 获取时间
- C# 根据当前时间获取本周、本月、本季度、本年的始末日期
- asp.net c# 打开新页面或页面跳转&&获取时间
- C#获取当前日期时间
- C#获取 Flv视频文件播放时间长度等信息
- C#获取获取北京时间多种方法
- C#获取内存图像数据流的方法
- 使用DateDiff方法来获取系统时间与指定时间的间隔数
- Java 获取时间间隔的方法
- C#获取当前日期时间(转)
- C#中的bitmap类和图像像素值获取方法
- Python获取间隔时间段的时间戳数据
- c#获取当前日期时间