android 存储图片到data目录和读取data目录下的图片
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 copy
- String str1 = "icon.png";
- FileOutputStream localFileOutputStream1 = openFileOutput(str1, 0);
- Bitmap.CompressFormat localCompressFormat = Bitmap.CompressFormat.PNG;
- bitmap.compress(localCompressFormat, 100, localFileOutputStream1);
- localFileOutputStream1.close();
[java] view plain copy
- String localIconNormal = "icon.png";
- FileInputStream localStream = openFileInput(localIconNormal);
- Bitmap bitmap = BitmapFactory.decodeStream(localStream));
android 存储图片到data目录和读取data目录下的图片的更多相关文章
- python 读取文件夹下的图片进行处理
python的os模块中有一个listdir函数可以遍历读取文件夹下的文件. import os for filename in os.listdir(r"./file"): #l ...
- Android存储Json到本地,和读取本地Json
/** * 保存json到本地 * @param mActivity * @param filename * @param content */ public static File dir = ne ...
- Android复制assets目录下的图片到内存
转自:http://www.chenwg.com/android/android%E5%A4%8D%E5%88%B6assets%E7%9B%AE%E5%BD%95%E4%B8%8B%E7%9A%84 ...
- Android调用系统相机和相册并解决data为空,OOM,图片角度不对的问题
最近公司项目用到手机拍照的问题,好不容易在网上copy了一些代码,但是运行起来一大堆bug,先是三星手机上运行程序直接崩掉,debug了一下原来是onActivityResult中data返回为空,找 ...
- 一篇文章搞懂android存储目录结构
前言 前两天因为开发一个app更新的功能,我将从服务器下载的apk文件放在了内部存储目录(测试手机为小米,路径为:data/user/0/packagename/files)下面,然后安装的时候一直安 ...
- Android存储访问及目录
Android存储访问及目录 Android的外部存储 Android支持外部存储(case-insensitive filesystem with immutable POSIX permissio ...
- android 读取sd卡中的图片
一.获取读取SD卡的权限 <!--在SDCard中创建与删除文件权限 --> <uses-permission android:name="android.perm ...
- [Android]利用run-as命令在不root情况下读取data下面的数据
正文 一.关键步骤 主要是run-as命令: over@over-ThinkPad-R52:~$ adb shell $ run-as com.package $ cd /data/data/co ...
- Android开发教程 - 使用Data Binding(七)使用BindingAdapter简化图片加载
本系列目录 使用Data Binding(一)介绍 使用Data Binding(二)集成与配置 使用Data Binding(三)在Activity中的使用 使用Data Binding(四)在Fr ...
随机推荐
- js自动更新时间+星期
<div class="top_bar" id="cao" height="28px"><script> setIn ...
- map set区别
STL中的容器有顺序容器 (vector,list,deque),关联容器(map,set)还有一些其他容器.根据不同的场合选择不同的容器,会有意想不到的收获. Map是单词mapping(映射)的缩 ...
- Outlook~设置
outlook2013 中帐户设置无法直接更改邮件投递位置到本地的.pst文件,“更改文件夹”选项已经删除. Exchange 传递到 Outlook 数据文件 (.pst) 升级到 Outlook ...
- JS中多种方式创建对象
1.内置对象创建 var girl=new Object(); girl.name='hxl'; console.log(typeof girl); 2.工厂模式,寄生构造函数模式 function ...
- Java的几种常用设计模式
何为设计模式? 就是对一些常见问题进行归纳总结,并针对具体问题给出一套通用的解决办法(强调的是解决问题的思想): 在开发中,只要遇到这类问题,就可以直接使用这些设计模式解决问题. ---------- ...
- hashmap实现原理浅析
看了下JAVA里面有HashMap.Hashtable.HashSet三种hash集合的实现源码,这里总结下,理解错误的地方还望指正 HashMap和Hashtable的区别 HashSet和Hash ...
- Intellij IDEA中的Mybatis Plugin破解
具体的破解过程请看:https://github.com/luyanliang/profile/blob/master/idea/plugin/MybatisPlugin/Mybatis-Plugin ...
- [译]:Orchard入门——构建你的第一个Orchard网站
原文链接:Building Your First Orchard Site 文章内容基于Orchard 1.8版本 本文将逐步简要介绍Orchard提供的功能.如果你是第一次使用Orchard,本文将 ...
- 使用lnmp一键安装包后yum源出现的问题与解决
遇到一个问题就是执行 Yum update 或使用yum安装软件等命令的时候会有一个链接报404,使用find查找到该链接与kbsingh-CentOS-Extras.repo这个包有关,删除后yum ...
- IIS8的证书设置
首先,打开IIS的网站,找到“服务器证书” 然后根据需要创建证书 创建好后,如果某一个网站(注意是网站,不是应用程序集)需要使用https则, 在右侧“绑定”一项中添加新的https连接,并选择对应的 ...