【发布时间】:2012-05-25 04:08:27
【问题描述】:
我认真地到处寻找,但找不到解决方案。 我的应用程序很容易将 UTF 字节保存为 XML 文件在 iOS 和 Android 允许的缓存位置。
但我不知道如何将 Bitmap / BitmapData 保存到同一缓存文件夹中的文件中。 创建文件很好....
_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);
}
【问题讨论】:
-
或blog.stroep.nl/2008/09/…你在看哪里?
-
感谢您的帮助,但仍然无法正常工作。运行 3 次,它保存 3 个文件大小不同的文件,但不显示图像...... addchild 在未注释时工作,所以我知道 Bitmap 有数据。我的代码现在在原来的问题上
标签: image actionscript-3 bitmap bitmapdata