1

I'm developing an iPad app using Adobe Air.

I have all my images loaded into BitmapData objects when the app starts. Then I only need to create Bitmap objects (which are only containers) to use the pixels that are stored into the BitmapDataobjects.

This works fine until I have to create a Bitmap object with a big image. The app slows down, even freezes, for as much as 1 second.

As AS3 is single threaded, I cannot delegate the Bitmap creation to a new thread. Also if the UI is frozen, I cannot show a decent spinner to inform the user "something is going on".

How could I solve this problem? Is there a way to create objects in parallel without affecting the UI performance?

4

2 回答 2

1

你可以使用一个worker,它基本上是 as3 的后台线程,在这里阅读它ASDocs Worker

于 2013-06-26T19:13:14.913 回答
0

好吧,答案似乎要简单得多,而 Adob​​e 已经想到了这一点。

http://help.adobe.com/en_US/as3/dev/WS52621785137562065a8e668112d98c8c4df-8000.html

问题是即使图像被加载到BitmapData对象中,它们仍然没有被解码。这就是为什么较大的图像需要一段时间才能放入Bitmap对象中。

解决方案就像在加载图像时使用指令强制图像解码一样简单,而不是在您需要它们时。这是使用ImageDecodingPolicy.ON_LOAD.

var loaderContext:LoaderContext = new LoaderContext(); 
loaderContext.imageDecodingPolicy = ImageDecodingPolicy.ON_LOAD; 
var loader:Loader = new Loader(); 
loader.load(new URLRequest("http://www.adobe.com/myimage.png"), loaderContext);
于 2013-06-26T20:27:04.060 回答