I seriously looked everywhere, but I can not find a solution. My application easily saves UTF bytes as XML files in the allowed cache cells for both iOS and Android.
But I can not decide how to save Bitmap / BitmapData to a file in the same cache folder. Creating the file is fine ....
_fs.open(_f, FileMode.WRITE);
_fs.close();
Any help on this would be greatly appreciated.
thank
UPDATE: The code is as follows:
_smallLogo = Bitmap(_loader.content);
var jpg:JPGEncoder = new JPGEncoder(100);
var bd:BitmapData = new BitmapData(_smallLogo.width, _smallLogo.height);
bd.draw(_smallLogo);
var ba:ByteArray = jpg.encode(bd);
_fs.open(_f, FileMode.WRITE);
_fs.writeBytes( ba, 0, ba.length );
_fs.close();
UPDATE - ANSWERED
_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();
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);
}
source
share