Flash 11.3推出了新的API,貌似能将图片压缩成ByteArray,这个也许很有用。貌似能压缩10-20倍的大小。也许图片可以通过这个来压缩加载,甚至缓存到内存里面。
public function encode(rect:Rectangle, compressor:Object, byteArray:ByteArray = null):ByteArray
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 11.3, AIR 3.3 |
Compresses this BitmapData object using the selected compressor algorithm and returns a new ByteArray object. Optionally, writes the resulting data to the specified ByteArray. The compressor
argument specifies the encoding algorithm, and can be PNGEncoderOptions, JPEGEncoderOptions, or JPEGXREncoderOptions.
The following example compresses a BitmapData object using the JPEGEncoderOptions:
// Compress a BitmapData object as a JPEG file.
var bitmapData:BitmapData = new BitmapData(640,480,false,0x00FF00);
var byteArray:ByteArray = new ByteArray();
bitmapData.encode(new Rectangle(0,0,640,480), new flash.display.JPEGEncoderOptions(), byteArray);
Parameters
| rect:Rectangle — The area of the BitmapData object to compress. |
|
| compressor:Object — The compressor type to use. Valid values are: flash.display.PNGEncoderOptions , flash.display.JPEGEncoderOptions , andflash.display.JPEGXREncoderOptions . |
|
| byteArray:ByteArray (default = null ) — The output ByteArray to hold the encoded image. |
Returns
| ByteArray — A ByteArray containing the encoded image. |
转载http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#encode()