码迷,mamicode.com
首页 > 移动开发 > 详细

android 存储图片到data目录和读取data目录下的图片

时间:2016-12-14 21:09:11      阅读:342      评论:0      收藏:0      [点我收藏+]

标签:code   style   icon   view   string   流程   .net   splay   out   

public void storePic(String tabid, String key, Bitmap bitmap) {
LogUtils.LOGD(TAG, "storePic begin tabid = " + tabid + "key = " + key);
FileOutputStream fos = null;
try {
fos = getActivity().openFileOutput(tabid + "_" + key, Context.MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
} catch (FileNotFoundException e) {
LogUtils.LOGE(TAG, "storePic FileNotFoundException e = " +e);
} finally {
if(fos != null) {
try {
fos.flush();
fos.close();
} catch (IOException e) {
LogUtils.LOGE(TAG, "storePic IOException e = " +e);
}
}
}
}

public Bitmap getStorePic(String tabid, String key) {
LogUtils.LOGD(TAG, "getStorePic begin tabid = " + tabid + "key = " + key);
FileInputStream fin = null;
Bitmap bitmap = null;
try {
fin = getActivity().openFileInput(tabid + "_" + key);
bitmap = BitmapFactory.decodeStream(fin);
} catch (FileNotFoundException e) {
LogUtils.LOGE(TAG, "getStorePic FileNotFoundException e = " + e);
}
return bitmap;
}


总而流程:
存储图片代码:

[java] view plain copy
  1. String str1 = "icon.png";  
  2.   
  3. FileOutputStream localFileOutputStream1 = openFileOutput(str1, 0);  
  4.   
  5. Bitmap.CompressFormat localCompressFormat = Bitmap.CompressFormat.PNG;  
  6.   
  7. bitmap.compress(localCompressFormat, 100, localFileOutputStream1);  
  8.   
  9. localFileOutputStream1.close();  

读取图片代码:

[java] view plain copy
  1. String localIconNormal = "icon.png";  
  2.   
  3. FileInputStream localStream = openFileInput(localIconNormal);  
  4.   
  5. Bitmap bitmap = BitmapFactory.decodeStream(localStream));  

android 存储图片到data目录和读取data目录下的图片

标签:code   style   icon   view   string   流程   .net   splay   out   

原文地址:http://www.cnblogs.com/wxmdevelop/p/6180762.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!