I am wondering if there is any way to determine the width and height of an image that is decoded to a ByteArray. For example in the below, any way to determine these values for data?
var data:ByteArray = new ByteArray();
data = encoded_image.decode(byteArrayData);
You can do it like this:
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 downside is that the whole image is going to be decoded, so if you don't actually need the image, but only the width and height, you might actually want to look in the byte array and decode the file format. (More tricky, but
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With