如何从原始字节数组中获取GIF图像尺寸?
以下是related问题。我试图找出是否有一个包含宽度和高度的字节字符串。
我在GIF格式上找到了this页,但我不确定如何解读它。它看起来像位置6和位置8包含宽度和高度?
答案 0 :(得分:5)
我认为这就是你要找的东西:http://www.matthewflickinger.com/lab/whatsinagif/bits_and_bytes.asp
字节6-7(基于0的索引)表示宽度,字节8-9表示高度。在那种情况下:
var source:ByteArray;
var aHeight:int;
var aWidth:int;
source.position = 6;
aWidth = source.readUnsignedByte();
aWidth += source.readUnsignedByte() << 8;
aHeight = source.readUnsignedByte();
aHeight += source.readUnsignedByte() << 8;
或者只是使用readShort
来获取双字节值(16位)而没有位移<<
......
aWidth = source.readShort();
aHeight = source.readShort();