1

Is there a way to turn the ByteArray back into a BitmapData after using BitmapData.encode()?

Anonymous1
  • 3,877
  • 3
  • 28
  • 42
  • possible duplicate of [ByteArray to BitmapData AS3](http://stackoverflow.com/questions/11541730/bytearray-to-bitmapdata-as3) – weltraumpirat Jul 25 '13 at 08:22

1 Answers1

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