Android加载图片导致内存溢出(Out of Memory异常)
来源:互联网 发布:74hc595数据手册 编辑:程序博客网 时间:2024/05/16 12:57
InputStream is = this.getResources().openRawResource(R.drawable.pic1);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = false;
options.inSampleSize = 10; // width,hight设为原来的十分一
Bitmap btp = BitmapFactory.decodeStream(is, null, options);
/**
* 以最省内存的方式读取本地资源的图片
* @param context
* @param resId
* @return
*/
public static Bitmap readBitMap(Context context, int resId){
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inPreferredConfig = Bitmap.Config.RGB_565;
opt.inPurgeable = true;
opt.inInputShareable = true;
// 获取资源图片
InputStream is = context.getResources().openRawResource(resId);
return BitmapFactory.decodeStream(is, null, opt);
}
if(imageView != null && imageView.getDrawable() != null){
Bitmap oldBitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
imageView.setImageDrawable(null);
if(oldBitmap != null){
oldBitmap.recycle();
oldBitmap = null;
}
}
// Other code.
System.gc();
BitmapFactory.Options opts = new BitmapFactory.Options();
// 设置inJustDecodeBounds为true
opts.inJustDecodeBounds = true;
// 使用decodeFile方法得到图片的宽和高
BitmapFactory.decodeFile(path, opts);
// 打印出图片的宽和高
Log.d("example", opts.outWidth + "," + opts.outHeight);
private final static float TARGET_HEAP_UTILIZATION = 0.75f;
// 在程序onCreate时就可以调用
VMRuntime.getRuntime().setTargetHeapUtilization(TARGET_HEAP_UTILIZATION);
private final static int CWJ_HEAP_SIZE = 6 * 1024 * 1024 ;
VMRuntime.getRuntime().setMinimumHeapSize(CWJ_HEAP_SIZE); // 设置最小heap内存为6MB大小。
- Android加载图片导致内存溢出(Out of Memory异常
- Android加载图片导致内存溢出(Out of Memory异常)
- Android加载图片导致内存溢出(Out of Memory异常)
- Android加载图片导致内存溢出(Out of Memory异常)
- Android加载图片导致内存溢出(Out of Memory异常)
- Android加载图片导致内存溢出(Out of Memory异常)
- Android加载图片导致内存溢出(Out of Memory异常)
- Android加载图片导致内存溢出(Out of Memory异常)
- Android加载图片导致内存溢出(Out of Memory异常)
- Android加载图片导致内存溢出(Out of Memory异常)
- Android加载图片导致内存溢出(Out of Memory异常)
- Android加载图片导致内存溢出(Out of Memory异常)
- Android加载图片导致内存溢出(Out of Memory异常)
- Android 加载图片过程导致内存溢出(Out Of Memory)
- Android 图片内存溢出(Out of Memory)
- 安卓加载大背景图片或者加载大量本地资源图片时经常导致内存溢出(Out of Memory Error)推荐几种解决方案
- android内存溢出问题(out of memory)
- Android内存溢出(Out Of Memory)…
- 嵌入式Linux系统图形及图形用户界面综述--2005-04-20博客搬家
- linq读写dt
- android删除文件出错
- erlang 压力测试工具 tsung
- Axure实现淡入淡出效果
- Android加载图片导致内存溢出(Out of Memory异常)
- 用SharedPreferences做setting(设置界面)
- 解决spring使用动态代理类型转换失败的问题--java.lang.ClassCastException: com.sun.proxy.$Proxy$ cannot be cast to ...
- 关于struct大小的计算
- Ubuntu 14.04 java环境安装配置(不是openJAVA)
- Windows + Apache 2.2+Tomcat7 集群配置
- Dictionary学习总结
- 给程序员推荐一些提高工作效率的工具
- 雪中的女孩--2005-02-21 博客搬家