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 ...
随机推荐
- jstl
今日内容 l JSTL标签库 l EL函数 l 自定义标签库开发 l JSP模式和案例(*****) 1.1 上次课内容总结 JSP技术: * JSP:Java Server Pages * JSP运 ...
- RF执行顺序
case: 按照定义的上下位置顺序执行,通过Ctrl+上下方向键,来改变执行次序. 包含suite的目录:按字母顺序. suite: 按字母顺序执行.可以加01__xxx.txt这样的前缀来控制顺序.
- ABAP BAPI 销售订单生产交货单函数
TYPES: BEGIN OF ty_so, vbeln LIKE vbap-vbeln, posnr LIKE vbap-posnr, END ...
- Fitbit Flex
Fitbit Flex 使用 7月4日,收到了在美国亚马逊上海淘的Fitbit Flex.首先谈谈这价格,在美国亚马逊上购买时的价格是98美元,下订单过后没几天,京东开始首发出售,价格定在898元.相 ...
- php解析.csv文件
public function actionImport() { //post请求过来的 $fileName = $_FILES['file']['name']; $fileTmpName = $_F ...
- 使用jquery实现单选框、多选框取消选中状态
function radioReset(){ /*方式一*/ /* var radios = $("input[type='radio']"); for (i=0; i<ra ...
- 解决 eclipse中properties文件编码问题
菜单——>Preferences——>General——>ContentTypes——>Text——>Java Properties File,设置Default enc ...
- c语言中遇到“警告: the `gets' function is dangerous and should not be used.”的解决办法
写于2016年12月1日. 在用c的库函数gets(str)时,编译出现该提示.原因在于linux下gcc不支持gets命令,要换成fgets(arr,size,stdin).
- linux服务器做网关
首先创建两张路由表,只需要添加到相应的文件中即可,Linux一共支持255个路由表,rt_tables文件中默认已经存在了三张路由表,分别是: 255 local 254 main ...
- ASP.NET4.5Web API及非同步程序开发系列(3)
接着上一篇博客的内容做一个补充,正好是一个大哥提出来的,我们看看一个有趣的现象. 请求相关问题的补充: 我们先在Controller中的定义一个我们在前一篇博客中已经测试过的方法如下: public ...