读书人

将bitmap保存为资料

发布时间: 2012-06-26 10:04:14 作者: rapoo

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

? ? ? ? }

? ? }?

读书人网 >移动开发

热点推荐