将图像从资源加载到arraylist时出现异常错误。 这是log cat中的错误: E / AndroidRuntime(2837):java.lang.OutOfMemoryError:位图大小超过VM预算
请有人帮助我,提前致谢
答案 0 :(得分:0)
有一次,我试图重新调整图像大小,我也有同样的问题,我使用下面的代码,你可以像你的一样修改,
public Bitmap custom_SizedImage(String intent_data2) {
Options options = new Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(intent_data2, options);
double sampleSize = 0;
Boolean scaleByHeight = Math.abs(options.outHeight - targetHeight) >= Math
.abs(options.outWidth - targetWidth);
if (options.outHeight * options.outWidth * 2 >= 1638) {
sampleSize = scaleByHeight ? options.outHeight / targetHeight
: options.outWidth / targetWidth;
sampleSize = (int) Math.pow(2d,
Math.floor(Math.log(sampleSize) / Math.log(2d)));
}
options.inJustDecodeBounds = false;
options.inTempStorage = new byte[128];
while (true) {
try {
options.inSampleSize = (int) sampleSize;
// here you can do you Decode process
//mBitmap = BitmapFactory.decodeFile(intent_data2, options);
break;
} catch (Exception ex) {
try {
sampleSize = sampleSize * 2;
} catch (Exception ex1) {
}
}
}
return scaledBitmap;
}