如何获得gif帧与帧的延时 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ref:http://blog.csdn.net/knight94/archive/2006/07/03/871038.aspx 谢谢愚翁的链接,不过里面只有gif的分解.我的目的是把分解后的gif逐帧显示,gif每帧之间肯定有延时,而且是不一样的,这个延时如何获得呢? 自己解决了,gif文件本身存储有每帧的延时,可以利用PropertyItem取出来 如果仅仅是为了显示Gif,不需要这么复杂,直接用ImageAnimator就可以了。http://blog.csdn.net/Mittermeyer/archive/2006/08/28/1131535.aspx 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 关于程序员应该靠什么认证的问题?麻烦给点意见!跪求进来关注! 想考高级软件设计师,有意义吗?? 请教各位高手一个即时通信的问题。 如何获取指定IP的MAC地址。 C#送分问题19 请问如何用C#处理麦克风输入和存储哪?谢谢 编程入门 为什么无法使用新建的xml对象 datagrid的小问题在线等ing.......... 我装不上VS.NET怎么办? 求助:有关过程调用问题 -----DataGridView绑定问题
http://blog.csdn.net/knight94/archive/2006/07/03/871038.aspx
{
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