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

时间:2017-01-16 06:42:52

标签: actionscript-3 flash air gif

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

以下是related问题。我试图找出是否有一个包含宽度和高度的字节字符串。

我在GIF格式上找到了this页,但我不确定如何解读它。它看起来像位置6和位置8包含宽度和高度?

1 个答案:

答案 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();