as3
import flash.display.BitmapData;
import flash.utils.ByteArray;
import flash.filesystem.*;
import com.adobe.images.JPGEncoder;
var bmpd:BitmapData = new BitmapData(mc.width,mc.height);
bmpd.draw(mc);
//create a new instance of the encoder, and set the jpeg compression level from 0 to 100
var jpgenc:JPGEncoder = new JPGEncoder(80);
//encode the bitmapdata object and keep the encoded ByteArray
var imgByteArray:ByteArray = jpgenc.encode(bmpd);
var file:File = File.desktopDirectory.resolvePath("snapshot.jpg");
//Use a FileStream to save the bytearray as bytes to the new file
var fs:FileStream = new FileStream();
try{
//open file in write mode
fs.open(file,FileMode.WRITE);
//write bytes from the byte array
fs.writeBytes(imgByteArray);
//close the file
fs.close();
}catch(e:Error){
trace(e.message);
}
使用说明:
此代码是用flash cs4开发的air的代码.mc 为舞台上的一个影片剪辑.
JPGEncoder是Adobe的一个as3工具类,用于将可视化元件编码为Jpg图像,可以在google或baidu中搜索下载到
windows下运行Air此图片自动保存到桌面