将图像从资产加载到数组列表时出现异常错误。这是日志中的错误 cat: E/AndroidRuntime(2837): java.lang.OutOfMemoryError: bitmap size超出VM budget
请有人帮我解决这个问题,在此先感谢
将图像从资产加载到数组列表时出现异常错误。这是日志中的错误 cat: E/AndroidRuntime(2837): java.lang.OutOfMemoryError: bitmap size超出VM budget
请有人帮我解决这个问题,在此先感谢
有一次,我尝试重新调整图像大小,我也遇到了同样的问题,我使用了下面的代码,您可以根据自己的需要进行修改,
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;
}