比较用decodeFileDescriptor和decodeFile的区别
从本地中读取图片,可以用decodeFileDescriptor和decodeFile,至于哪一种方式的耗内存情况作了一次简单对比,可能一次选取6张图片数量过少,貌似区别不大,decodeFileDescriptor能节省1.6mb左右:
1、decodeFileDescriptor的读取6张图片(中间包含压缩、读取、转Base64)


2、decodeFile的读取6张图片(中间包含压缩、读取、转Base64)


public static Bitmap decodeSampledBitmapFromFile(String filepath,int reqWidth,int reqHeight) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
FileInputStream is = null;
Bitmap bitmap = null;
try {
is = new FileInputStream(filepath);
BitmapFactory.decodeFileDescriptor(is.getFD(),null, options);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
options.inSampleSize = calculateInSampleSize(options, reqWidth,reqHeight);
options.inJustDecodeBounds = false;
try {
bitmap = BitmapFactory.decodeFileDescriptor(is.getFD(),null, options);
} catch (IOException e) {
e.printStackTrace();
}finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
// do nothing here
}
}
}
return bitmap;
}
public static Bitmap decodeSampledBitmapFromFile2(String filepath,int reqWidth,int reqHeight) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filepath, options);
options.inSampleSize = calculateInSampleSize(options, reqWidth,reqHeight);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(filepath, options);
}
再上50张图片的对比:


decodeFileDescriptor一共用了34mb


decodeFile触发GCC自动回收内存了??
这里再回头看看压缩处理后的代码:
for(int i=0 ; i<mSelectPath.size();i++){
String path = mSelectPath.get(i);
//压缩处理(需要提示)
Bitmap bitmap = PictureUtil.decodeSampledBitmapFromFile(path,MyConfig.PicMaxWidth,MyConfig.PicMaxHeight);
//保存图片到相应文件夹(质量可能变差)
// PictureUtil.saveBitmapWithCompress(bitmap,50,filesList);
if(!bitmap.isRecycled() ){
bitmap.recycle(); //回收图片所占的内存
System.gc(); //提醒系统及时回收
}
}
通过添加bitmap内存回收和释放:
decodeFileDescriptor的使用情况如下:


这是只使用了16mb
比较用decodeFileDescriptor和decodeFile的区别的更多相关文章
- c#与java的区别
经常有人问这种问题,用了些时间java之后,发现这俩玩意除了一小部分壳子长的还有能稍微凑合上,基本上没什么相似之处,可以说也就是马甲层面上的相似吧,还是比较短的马甲... 一般C#多用于业务系统的开发 ...
- jquery和Js的区别和基础操作
jqery的语法和js的语法一样,算是把js升级了一下,这两种语法可以一起使用,只不过是用jqery更加方便 一个页面想要使用jqery的话,先要引入一下jqery包,jqery包从网上下一个就可以, ...
- 【原】nodejs全局安装和本地安装的区别
来微信支付有2年多了,从2年前的互联网模式转变为O2O模式,主要的场景是跟线下的商户去打交道,不像以往的互联网模式,有产品经理提需求,我们帮忙去解决问题. 转型后是这样的,团队成员更多需要去寻找业务的 ...
- 探究@property申明对象属性时copy与strong的区别
一.问题来源 一直没有搞清楚NSString.NSArray.NSDictionary--属性描述关键字copy和strong的区别,看别人的项目中属性定义有的用copy,有的用strong.自己在开 ...
- X86和X86_64和X64有什么区别?
x86是指intel的开发的一种32位指令集,从386开始时代开始的,一直沿用至今,是一种cisc指令集,所有intel早期的cpu,amd早期的cpu都支持这种指令集,ntel官方文档里面称为&qu ...
- Java中Comparable与Comparator的区别
相同 Comparable和Comparator都是用来实现对象的比较.排序 要想对象比较.排序,都需要实现Comparable或Comparator接口 Comparable和Comparator都 ...
- MySQL中interactive_timeout和wait_timeout的区别
在用mysql客户端对数据库进行操作时,打开终端窗口,如果一段时间没有操作,再次操作时,常常会报如下错误: ERROR (HY000): Lost connection to MySQL server ...
- 设置line-height:1.5和line-height:150%或者line-height:150px的区别
直接正题: 看一下line-height可能的值: 其实可以分为两类: (1)不带单位的(如line-height:1.5),这种是推荐使用的: (2)带单位的(如line-heigth:30px/1 ...
- C#中Length和Count的区别(个人观点)
这篇文章将会很短...短到比你的JJ还短,当然开玩笑了.网上有说过Length和count的区别,都是很含糊的,我没有发现有 文章说得比较透彻的,所以,虽然这篇文章很短,我还是希望能留在首页,听听大家 ...
随机推荐
- 使用Resource Owner Password Credentials Grant授权发放Token
对应的应用场景是:为自家的网站开发手机 App(非第三方 App),只需用户在 App 上登录,无需用户对 App 所能访问的数据进行授权. 客户端获取Token: public string Get ...
- Swift 遍历数组元素
..<Array.count { Array[index] } for (index, element) in Array.enumerate() { print(("\(index+ ...
- 多媒体技术基础之---Come on!来点儿音乐吧
其实要说在Linux系统下播放音乐,确实是一件让人非常抓狂的事情,抛开各种音频格式的商业授权不说,即使提供给你相应的解码库,能玩儿得转的人那又是少之又少.可能有些盆友说ubuntu这方面确实做得不错, ...
- javascript arguments与javascript函数重载
1.所 有的函数都有属于自己的一个arguments对象,它包括了函所要调用的参数.他不是一个数组,如果用typeof arguments,返回的是’object’.虽然我们可以用调用数据的方法来调用 ...
- iOS静态库.a文件制作和导入使用
iOS静态库.a文件制作: 1.新建Cocoa Touch Static Library工程 新建工程 - 选择iOS-FrameWork&Libary,选择 Cocoa Touch Stat ...
- MySQL~ IN , FIND_IN_SET , LIKE
MySQL- IN , FIND_IN_SET , LIKE SELECT * FROM test where area IN (1, 2, 3); SELECT * FROM test where ...
- 【Linux】LAMP环境的搭建
LAMP定义 LAMP指的Linux(操作系统).ApacheHTTP 服务器,MySQL(有时也指MariaDB,数据库软件) 和PHP(有时也是指Perl或Python) 的第一个字母,一般用来建 ...
- Exception-异常
异常(Exception)是程序执行过程中所产生的问题 产生原因:用户输入无效数字.找不到需要打开的文件.在通讯中网络连接中断.JVM发生了内存溢出 异常的三个种类:检查异常.运行时异常.错误(类似异 ...
- 打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方。
public class Three_03 { public static void main(String[] args) { for(int i=100;i<1000;i++){ int a ...
- java线程详解(三)
java线程间通信 首先看一段代码 class Res { String name; String sex; } class Input implements Runnable { private R ...