Getting image size from ByteArray

I am wondering if there is a way to determine the width and height of the image that is decoded in ByteArray. For example, in the following, is there any way to determine these values ​​for the data?

data var: ByteArray = new ByteArray ();

data = encoded_image.decode (byteArrayData);

+5
source share
2 answers

You can do it as follows:

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);
}

The disadvantage is that the whole image will be decoded, so if you really do not need the image, but only the width and height, you can really look into an array of bytes and decode the file format. (More complicated, but

+3
source

All Articles