如何从 AS3 中的字节数组获取 GIF 图像尺寸?

How to get the GIF image size dimensions from byte array in AS3?

如何从原始字节数组中获取 GIF 图像尺寸?

这里是 问题。我试图找出是否有一串包含宽度和高度的字节。

我找到了 GIF 格式的 this 页面,但我不确定如何破译它。貌似位置6和位置8包含了宽和高?

我想这就是您要找的: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 获取 two-byte 值(16 位)而不使用 bit-shifting <<...

aWidth  = source.readShort();
aHeight  = source.readShort();