Is there a way to turn the ByteArray back into a BitmapData after using BitmapData.encode()?
Asked
Active
Viewed 852 times
1
-
possible duplicate of [ByteArray to BitmapData AS3](http://stackoverflow.com/questions/11541730/bytearray-to-bitmapdata-as3) – weltraumpirat Jul 25 '13 at 08:22
1 Answers
4
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);

fsbmain
- 5,267
- 2
- 16
- 23
-
Well actually, it IS a way to "turn back" the ByteArray. +1 for good answer. – Aralicia Jul 25 '13 at 08:23