【发布时间】:2017-11-29 22:03:21
【问题描述】:
我有一个在我的手机上运行良好的。但是,当我检查实时崩溃数据时,人们会收到内存不足错误。
java.lang.OutOfMemoryError
我正在尝试从照片中加载图像并尝试使图像更小。
这是我的代码
所需大小为 1000
public static Bitmap getImage(Context c, Uri uri, final int requiredSize)
throws FileNotFoundException {
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(c.getContentResolver().openInputStream(uri), null, o);
int width_tmp = o.outWidth
, height_tmp = o.outHeight;
int scale = 1;
while(true) {
if(width_tmp / 2 < requiredSize || height_tmp / 2 < requiredSize)
break;
width_tmp /= 2;
height_tmp /= 2;
scale *= 2;
}
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
return BitmapFactory.decodeStream(c.getContentResolver().openInputStream(uri), null, o2); //This is the line that's getting the error
}
【问题讨论】:
标签: performance android-imageview android-image android-memory