private void saveBmpToSd(Bitmap bm, String url) {
if (bm == null || url==null) {
return;
}
if (10 >freeSpaceOnSd()) {
return;
}
String filename = url.replace("/", "").replace(":", "").replace(",", "")
.replace("\\", "").replace(".", "").replace("?", "").replace("|", "").replace("\"", "")
.replace(">", "").replace("<", "")+".png";
String dir = this.getExternalCacheDir().getAbsolutePath();
File file = new File(dir +"/" + filename);
if(!file.exists()) {
try {
file.createNewFile();
OutputStream outStream = new FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
} catch (IOException e) {
}
}
if(StringUtils.IsShowLog) {
//StringUtils.log(tag, "filename="+filename);
//StringUtils.log(tag, "dir="+dir);
}
}
本文介绍了一种将Bitmap对象保存为PNG格式文件的方法,并详细解释了如何检查存储空间、生成文件名、创建文件及写入数据的过程。
1483

被折叠的 条评论
为什么被折叠?



