首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

将bitmap保存为资料

2012-06-26 
将bitmap保存为文件?private void saveBmpToSd(Bitmap bm, String url) {? ? ? ? if (bm null || url

将bitmap保存为文件

?

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);

? ? ? ? }

? ? }?

热点排行