Drawable.createFromPath nativeDecodeStream OutOfMemoryError
来源:互联网 发布:kali linux wifi 劫持 编辑:程序博客网 时间:2024/06/06 05:13
一般解析图片进行指定大小,这样不容易造成内存溢出
public static Bitmap decodeBitmapFromRes(Resources res,int bmpId,int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;//设置这个,只得到能解析的出来图片的大小,并不进行真正的解析
BitmapFactory.decodeResource(res, bmpId, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); //跟指定大小比较,计算缩放比例
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res, bmpId, options);
}
public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
if (width > height) {
inSampleSize = Math.round((float)height / (float)reqHeight);
} else {
inSampleSize = Math.round((float)width / (float)reqWidth);
}
}
return inSampleSize;
}
参考:http://stackoverflow.com/questions/10278686/out-of-memory-fatal-exception
- Drawable.createFromPath nativeDecodeStream OutOfMemoryError
- (Bitmap OOM) BitmapFactory.nativeDecodeStream
- (Bitmap OOM) BitmapFactory.nativeDecodeStream
- outOfMemoryError
- outofmemoryerror
- OutOfMemoryError
- OutOfMemoryError
- OutOfMemoryError
- OutOfMemoryError
- OutOfMemoryError
- OutOfMemoryError
- OutOfMemoryError
- OutOfMemoryError
- OutOfMemoryError
- OutOfMemoryError
- OutOfMemoryError
- OutOfMemoryError
- OutOfMemoryError
- V4L2深入理解
- Uboot启动参数说明:
- yum命令常见参数
- 快速排序
- Keyboard
- Drawable.createFromPath nativeDecodeStream OutOfMemoryError
- 乔吉拉德18条经典名言
- 分布式与集群的关系和区别
- Addison.Wesley.Joomla.Explained.Jun.2011
- 【Linux】进程间通信-信号量详解及编程实例
- shell中的rpm -pi的意思
- oracle dba常用语句5
- 读书感想
- 为您解读CSS优先级