kenshinx
September 19th, 2009, 01:02 AM
Hi,
I'm trying to figure out the fastest possible way to load a .png image into a BitmapData object. I am performing multiple processes that do this (load a .png from filesystem). The progress is shown using a loading bar, and I would like to speed up the loading time. Now this process can be called over n number times (via a timer). Right now the method I am using to this is:
private function loadPNG(e:TimerEvent):void
{
var pngStream:FileStream = new FileStream();
pngStream.open(new File("path/to/png/file.png",FileMode.READ));
var pngBytes:ByteArray = new ByteArray();
pngStream.readBytes(pngBytes,0,pngStream.bytesAvai lable);
pngStream.close();
var pngLoader:Loader = new Loader();
pngLoader.width = pngLoader.height = 172;
pngLoader.contentLoaderInfo.addEventListener(Event .COMPLETE, finishLoading);
pngLoader.loadBytes(pngBytes);
}
private function finishLoading(e:Event):void
{
var png:Bitmap = new Bitmap();
png.bitmapData = new BitmapData(e.target.width, e.target.height, true, 0x00FF00);
png.bitmapData.draw(e.target.content)
}
I think the reason that my loading time is so slow is because it is asynchronous. It has to wait until the content is finished loading and then can move on. This loading speed is acceptable for about 170-200 times, but any higher than that and it seems like it takes forever.
Thanks.
I'm trying to figure out the fastest possible way to load a .png image into a BitmapData object. I am performing multiple processes that do this (load a .png from filesystem). The progress is shown using a loading bar, and I would like to speed up the loading time. Now this process can be called over n number times (via a timer). Right now the method I am using to this is:
private function loadPNG(e:TimerEvent):void
{
var pngStream:FileStream = new FileStream();
pngStream.open(new File("path/to/png/file.png",FileMode.READ));
var pngBytes:ByteArray = new ByteArray();
pngStream.readBytes(pngBytes,0,pngStream.bytesAvai lable);
pngStream.close();
var pngLoader:Loader = new Loader();
pngLoader.width = pngLoader.height = 172;
pngLoader.contentLoaderInfo.addEventListener(Event .COMPLETE, finishLoading);
pngLoader.loadBytes(pngBytes);
}
private function finishLoading(e:Event):void
{
var png:Bitmap = new Bitmap();
png.bitmapData = new BitmapData(e.target.width, e.target.height, true, 0x00FF00);
png.bitmapData.draw(e.target.content)
}
I think the reason that my loading time is so slow is because it is asynchronous. It has to wait until the content is finished loading and then can move on. This loading speed is acceptable for about 170-200 times, but any higher than that and it seems like it takes forever.
Thanks.