0
votes

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.

1
Using drawWithQuality and using StageQuality.LOW does nothing to increase performanceLiam Flaherty
Is the draw slow or the loading of the file slow ? Have you distinguished the time between those two processes ? Also, slow is rather vague, expressing the delay in real time units like seconds or milliseconds would be helpful.prototypical
The draw is slow, the loading is very quick. I do not know the exact time that it takes to draw but it is 1-2 seconds (which is not okay because I am programming a game)Liam Flaherty
How did you distinguish between the draw and the load times ? How often are you loading/drawing this bitmap ?prototypical
I commented out the draw code and there was no waiting timeLiam Flaherty

1 Answers

3
votes

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;
}