Question

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

Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top