异步解压Asynchronous decoding of bitmap images

Flash Player 11 and later, Adobe AIR 2.6 and later

When you work with bitmap images, you can asynchronously decode and load the bitmap images to improve your application’s perceived performance. Decoding a bitmap image asynchronously can take the same time as decoding the image synchronously in many cases. However, the bitmap image gets decoded in a separate thread before the associated Loader object sends the COMPLETE event. Hence, you can asynchronously decode larger images after loading them.

The ImageDecodingPolicy class in the flash.system package, allows you to specify the bitmap loading scheme. The default loading scheme is synchronous.

Bitmap Decoding Policy

Bitmap Loading Scheme

Description

ImageDecodingPolicy.ON_DEMAND

Synchronous

Loaded images are decoded when the image data is accessed.

Use this policy to decode smaller images. You can also use this policy when your application does not rely on complex effects and transitions.

ImageDecodingPolicy.ON_LOAD

Asynchronous

Loaded images are decoded on load, before the COMPLETE event is dispatched.

Ideal for larger images (greater than 10 MP). When you are developing AIR-based mobile applications with page transitions, use this bitmap loading policy to improve your application’s perceived performance.

Note: If the file being loaded is a bitmap image and the decoding policy used is  ON_LOAD, the image is decoded asynchronously before the  COMPLETE event is dispatched.

The following code shows the usage of the ImageDecodingPolicy class:

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

You can still use ON_DEMAND decoding with Loader.load() and Loader.loadBytes() methods. However, all the other methods that take a LoaderContext object as an argument, ignore any ImageDecodingPolicy value passed.

The following example shows the difference in decoding a bitmap image synchronously and asynchronously:

package 
{ 
    import flash.display.Loader;   
    import flash.display.Sprite;  
    import flash.events.Event; 
    import flash.net.URLRequest; 
    import flash.system.ImageDecodingPolicy; 
    import flash.system.LoaderContext; 
 
    public class AsyncTest extends Sprite 
    { 
        private var loaderContext:LoaderContext; 
        private var loader:Loader; 
        private var urlRequest:URLRequest;         
        public function AsyncTest() 
        { 
            //Load the image synchronously 
            loaderContext = new LoaderContext(); 
            //Default behavior. 
            loaderContext.imageDecodingPolicy = ImageDecodingPolicy.ON_DEMAND;             
            loader = new Loader();     
            loadImageSync();                     
             
            //Load the image asynchronously 
            loaderContext = new LoaderContext(); 
            loaderContext.imageDecodingPolicy = ImageDecodingPolicy.ON_LOAD;             
            loader = new Loader(); 
            loadImageASync();     
        } 
         
        private function loadImageASync():void{ 
            trace("Loading image asynchronously...");             
            urlRequest = new URLRequest("http://www.adobe.com/myimage.png");     
            urlRequest.useCache = false; 
            loader.load(urlRequest, loaderContext);                     
            loader.contentLoaderInfo.addEventListener 
                (Event.COMPLETE, onAsyncLoadComplete); 
        } 
         
        private function onAsyncLoadComplete(event:Event):void{             
            trace("Async. Image Load Complete"); 
        }     
     
        private function loadImageSync():void{             
            trace("Loading image synchronously...");             
            urlRequest = new URLRequest("http://www.adobe.com/myimage.png");     
            urlRequest.useCache = false; 
            loader.load(urlRequest, loaderContext); 
            loader.contentLoaderInfo.addEventListener 
                (Event.COMPLETE, onSyncLoadComplete); 
        } 
         
        private function onSyncLoadComplete(event:Event):void{             
            trace("Sync. Image Load Complete"); 
        } 
    } 
}

For a demonstration of the effect of the different decoding policies, see Thibaud Imbert: Asynchronous bitmap decoding in the Adobe Flash runtimes


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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值