对Bitmap的内存优化
来源:互联网 发布:软件交付风险 编辑:程序博客网 时间:2024/05/16 15:58
转载自 :"http://blog.csdn.net/arui319/article/details/7953690"
看了"Android开发优化之——对Bitmap的内存优化”后总结一下防止忘了
1) 要及时回收Bitmap的内存
//首先判断bitmap是否回收if(bitmap != null && !bitmap.isRecycled()){
// 回收并且置为null
bitmap.recycle();
bitmap = null;
}
2) 捕获异常
Bitmap bitmap = null;
try {// 实例化Bitmap
bitmap = BitmapFactory.decodeFile(path);
} catch (OutOfMemoryError e) {
//
}
if (bitmap == null) {
// 如果实例化失败 返回默认的Bitmap对象
return defaultBitmapMap;
}
如果不进行缓存,尽管看到的是同一张图片文件,但是使用BitmapFactory类的方法来实例化出来的Bitmap,是不同的Bitmap对象。缓存可以避免新建多个Bitmap对象,避免内存的浪费。
4) 压缩图片
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = 2;//宽高都变成原先的一半
Bitmap bm = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher,opts);
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;// 设置inJustDecodeBounds为true
BitmapFactory.decodeFile(path, opts);// 使用decodeFile方法得到图片的宽和高
int width = opts.outWidth;
int height = opts.outHeight;
0 0
- 对Bitmap的内存优化
- 对Bitmap的内存优化
- Android对Bitmap的内存优化
- Android中对Bitmap的内存优化
- Android内存优化三:对Bitmap的内存优化
- Android内存优化1-对Bitmap的内存优化
- Android内存优化三:对Bitmap的内存优化
- Bitmap 的内存优化
- Bitmap的内存优化
- Android应用开发中对Bitmap的内存优化
- Android应用开发中对Bitmap的内存优化
- Android应用开发中对Bitmap的内存优化
- Android应用开发中对Bitmap的内存优化
- Android应用开发中对Bitmap的内存优化
- Android应用开发中对Bitmap的内存优化
- Android应用开发中对Bitmap的内存优化
- Android应用开发中对Bitmap的内存优化
- Android应用开发中对Bitmap的内存优化
- ubuntu14.04搭建samba
- dcef3获取页面html代码
- 自定义对象里面的 针对 某个属性 / 字段 进行排序
- 使用C++将OpenCV中Mat的数据写入二进制文件,用Matlab读出
- iOS下的RSA加密方法
- 对Bitmap的内存优化
- rails优化二:不要更改参数哈希params[:q]
- OC中的语法糖(你真的理解了点语法么?)
- 自动删除oracle下的过期文件命令
- 计算一句话(英文)里面的单词数量
- c语言之坑--位运算
- Eclipse报错:the superclass "javax.servlet.http.HttpServlet" was not found on the java Build Path
- 位操作基础篇之位操作全面总结
- 安卓jni进阶