android 存储图片到data目录和读取data目录下的图片
2016-12-14 20:23
615 查看
public void storePic(String tabid, String key, Bitmap bitmap) { LogUtils.LOGD(TAG, "storePic begin tabid = " + tabid + "key = " + key); if(tabid == null || key == null || tabid.isEmpty() || key.isEmpty() || bitmap == null) { return; } 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); if(tabid == null || key == null || tabid.isEmpty() || key.isEmpty()) { return null; } 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 copyString str1 = "icon.png";FileOutputStream localFileOutputStream1 = openFileOutput(str1, 0);Bitmap.CompressFormat localCompressFormat = Bitmap.CompressFormat.PNG;bitmap.compress(localCompressFormat, 100, localFileOutputStream1);localFileOutputStream1.close();读取图片代码:[java] view plain copyString localIconNormal = "icon.png";FileInputStream localStream = openFileInput(localIconNormal);Bitmap bitmap = BitmapFactory.decodeStream(localStream));
相关文章推荐
- Android 自定义View 之 触摸消息派发
- Android开发——ViewPage制作滑动导航界面
- 我的Android进阶之旅------>解决:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
- Android极光推送入门
- android Animation动画平移之后不响应点击事件
- android代理模式,proxy模式简单分析
- Android动画-Frame Animation(帧动画)
- Android开发中的多线程
- Android设置Activity背景为透明style
- 国内免代理下载android源码
- Android安全加密:对称加密
- 这可能是最精简的Android6.0运行时权限处理,70行代码的工具类。附:各种权限详细处理
- android 在图形中间添加字体
- Android音乐编程:管理音频焦点
- android 使用Serializable接口
- Android开发之多线程编程Thread和Runnable使用
- Android线程的理解与使用
- Android 自定义View 饼图
- 安卓(Android)如何获取正在运行服务的详细信息
- firebase连接二三事