我已经认真地搜索了各个地方,但是找不到解决方案。 我的应用程序可以轻松地将UTF字节保存为XML文件,并且可以在iOS和Android的允许缓存位置中进行保存。
但是我无法弄清楚如何将位图/位图数据保存到同一缓存文件夹中的文件中。 创建文件很容易....
_fs.open(_f, FileMode.WRITE);
//What goes in here to save the Bitmap?
_fs.close();
任何关于这个的帮助都将不胜感激。
谢谢。
更新:代码如下...
_smallLogo = Bitmap(_loader.content);
//this.addChild(_smallLogo);
var jpg:JPGEncoder = new JPGEncoder(100);
var bd:BitmapData = new BitmapData(_smallLogo.width, _smallLogo.height);
bd.draw(_smallLogo);
var ba:ByteArray = jpg.encode(bd);
//3
_fs.open(_f, FileMode.WRITE);
_fs.writeBytes( ba, 0, ba.length );
_fs.close();
更新 - 已回答
//SAVE
_smallLogo = Bitmap(_loader.content);
var jpg:JPGEncoder = new JPGEncoder(100);
var ba:ByteArray = jpg.encode(_smallLogo.bitmapData);
_fs.open(_f, FileMode.WRITE);
_fs.writeBytes( ba, 0, ba.length );
_fs.close();
//OPEN
private function getLogo():void {
var ba:ByteArray = new ByteArray();
_fs.open(_f, FileMode.READ);
_fs.readBytes(ba);
_fs.close();
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, getBitmapData);
loader.loadBytes(ba);
}
private function getBitmapData(e:Event):void {
var decodedBitmapData:BitmapData = Bitmap(e.target.content).bitmapData;
var newBMP:Bitmap = new Bitmap();
newBMP.bitmapData = decodedBitmapData;
this.addChild(newBMP);
}