我有一个可以在我的手机上正常工作的。然而,当我检查实时崩溃数据时,人们得到了内存不足的错误。
java.lang.OutOfMemoryError
我试图从照片加载图像,并试图使图像更小。
这是我的代码
requiredSize为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
}
https://stackoverflow.com/questions/47562619
复制相似问题