Android加载图片导致内存溢出(Out of Memory异常)
来源:互联网 发布:access是数据库软件吗 编辑:程序博客网 时间:2024/05/16 09:03
Android加载图片导致内存溢出(Out of Memory异常)
2013-02-28 18:49:26| 分类: Android | 标签:加载 图片 内存 溢出 outofmemory |举报 |字号 订阅
InputStream is = this.getResources().openRawResource(R.drawable.pic1);
BitmapFactory.Options options = newBitmapFactory.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)…
- AsyncTask的用法
- 请为main函数提供返回值
- MFC ------- AfxGetMainWnd( )
- unity3d的日历控件
- js url传值中文乱码之解决之道
- Android加载图片导致内存溢出(Out of Memory异常)
- Linux下C语言的编译全过程解读
- Ubuntu 解决 shell ./ 没有那个文件或目录 而ls有 的方法
- Spring定时任务的几种实现
- 客户端(浏览器)错误讯息
- linux并发控制之读写信号量
- PHP大批量插入数据库的3种方法和速度对比
- Tiled实现斜45度瓦片地图
- linux并发控制之完成量