Reputation: 3907
Is there a way to turn the ByteArray back into a BitmapData after using BitmapData.encode()?
Upvotes: 1
Views: 883
Reputation: 445
Introduced with AIR 50.0
there now is BitmapData.decode()
:
Decompresses encoded image data (PNG/GIF89a/JPEG) into a new BitmapData object using data provided in a ByteArray. The image format is determined by the runtime and supports the same formats as can be provided within a SWF file's DefineBitsJPEG2 tag.
https://airsdk.dev/reference/actionscript/3.0/flash/display/BitmapData.html#decode()
Upvotes: 0
Reputation: 5267
No, there isn't. You have to use Loader
to load encoded JPEG and access bitmap data through the loaded content:
var bitmap:Bitmap = new Bitmap(new BitmapData(100, 100, false, 0xFF0000));
addChild(bitmap);
var bytes:ByteArray = new ByteArray();
bitmap.bitmapData.encode(bitmap.bitmapData.rect, new JPEGEncoderOptions(), bytes);
bitmap.bitmapData.dispose();
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(event:Event):void
{
var bd:BitmapData = Bitmap(LoaderInfo(event.target).content).bitmapData;
bitmap.bitmapData = bd;
});
loader.loadBytes(bytes);
Upvotes: 4