Fast or asynchronous AS3 JPEG encoding

后端 未结 5 1738
野趣味
野趣味 2020-12-18 05:42

I\'m currently using the JPGEncoder from the AS3 core lib to encode a bitmap to JPEG

 var enc:JPGEncoder = new JPGEncoder(90);
 var jpg:ByteArra         


        
相关标签:
5条回答
  • 2020-12-18 06:27

    You can use the alchemy encoder. It is really fast and you can encode images asynchronously. You can use this class to abstract it.

    public class JPGAlchemyEncoder {
    
        private static var alchemyWrapper:Object;
        private var quality:Number;
    
        public function JPGAlchemyEncoder(quality:Number) {
            this.quality = quality;
            if (!alchemyWrapper){
                var loader:CLibInit = new CLibInit;
                alchemyWrapper = loader.init();
            }
        }
    
        public function encode(bitmapData:BitmapData):ByteArray{
            var data: ByteArray = bitmapData.clone().getPixels( bitmapData.rect );
            data.position = 0;
            return alchemyWrapper.write_jpeg_file(data, bitmapData.width, bitmapData.height, 3, 2, quality);
        }
    
        public function encodeAsync(bitmapData:BitmapData, completeHandler:Function):void{
            var encodedData:ByteArray = new ByteArray();
            var data: ByteArray = bitmapData.clone().getPixels(bitmapData.rect);
            data.position = 0;
            var encodeComplete:Function = function():void{
                completeHandler(encodedData);
            };
            alchemyWrapper.encodeAsync(encodeComplete, data, encodedData, bitmapData.width, bitmapData.height, quality);
        }
    }
    }
    
    0 讨论(0)
  • 2020-12-18 06:28

    I found an asynchronous encoder: http://www.switchonthecode.com/tutorials/flex-tutorial-an-asynchronous-jpeg-encoder

    0 讨论(0)
  • 2020-12-18 06:30

    asynchronous decode the png picture in separate thread ,supported by new version ...

    var loaderContext:LoaderContext = new LoaderContext();
    loaderContext.imageDecodingPolicy = ImageDecodingPolicy.ON_LOAD;
    
    var loader:Loader = new Loader();
    loader.load(new URLRequest("...png"),loaderContext);
    addChild(loader);
    

    that's official.

    0 讨论(0)
  • 2020-12-18 06:36

    Setting up the encoder to be asynchronous would likely be your best bet.

    Here are two examples from Adobe

    This example is with actionscript/flex, but its the same idea.

    0 讨论(0)
  • 2020-12-18 06:45

    You can do it much faster with Alchemy: http://www.websector.de/blog/2009/06/21/speed-up-jpeg-encoding-using-alchemy/

    http://segfaultlabs.com/devlogs/alchemy-asynchronous-jpeg-encoding-2

    0 讨论(0)
提交回复
热议问题