Reputation: 337
I am using ActionScript 3 in Flash CS6 with Adobe AIR 3.4
I am trying to load an image from the file system into a Bitmap.
My current code is:
var loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
loader.load(new URLRequest("assets\\" + filename));
private function loadComplete(e:Event):void
{
//add to bitmap
bitmap = new Bitmap();
bitmap.bitmapData = new BitmapData(loader.width, loader.height, true, 0x000000);
bitmap.bitmapData.draw(loader);
}
However there is very inefficient performance at bitmapData.draw (the image is 2048x1536). I have tried:
bitmap.bitmapData = e.target.content.bitmapData;
However it does not affect the performance. And is still very slow.
How can I load the image in the loader into a Bitmap without having such slow performance.
Upvotes: 0
Views: 1788
Reputation: 4870
When you load an image with a Loader
, you already get a Bitmap
. So why do you draw()
into another one?
Just do this:
private function loadComplete(event:Event):void
{
bitmap = loader.contentLoaderInfo.content as Bitmap;
}
Upvotes: 3