actionscript-3 - 从 ByteArray 获取图像大小

标签 actionscript-3 flash-cs5

我想知道是否有任何方法可以确定解码为 ByteArray 的图像的宽度和高度。例如在下面,有什么方法可以确定数据的这些值?

var data:ByteArray = new ByteArray();

数据 = 编码图像。解码(字节数组数据);

最佳答案

你可以这样做:

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded)
loader.loadBytes(byteArrayData);

——
function onLoaded(e:Event):void
{
    var loader:Loader = Loader(e.target.loader);
    var bitmapData:BitmapData = Bitmap(e.target.content).bitmapData;

    width = bitmapData.width;
    height = bitmapData.height;

    // cleanup
    loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onLoaded);
}

缺点是整个图像都将被解码,因此如果您实际上不需要图像,而只需要宽度和高度,您可能实际上想要查看字节数组并解码文件格式。 (更棘手,但

关于actionscript-3 - 从 ByteArray 获取图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7895093/

相关文章:

flash - 使用 ActionScript 3 将鼠标事件监听器添加到位图

算法找到网格上所有单元格的最短路径

flash - 键盘事件 as3 不工作

actionscript-3 - 如何以编程方式访问显示对象的所有子对象?

javascript - 在 Adob​​e Animate CC 中添加鼠标悬停指针

由 C# Photoshop CS5 Scripting 编写

android - 适用于 Android 的 Adob​​e Flash Professional CS6 : Navigate from One movie-clip to another move-clip using Actionscript 3 class

flash - 当 scrollDrag=true 时,ScrollPane/endDrag() 中的空对象引用

actionscript-3 - == 和 === 有什么区别?

variables - 为什么函数会声明 "myVariable = myVariable;"?