图片压缩异常;无法分配 629749908 字节分配 16777216 空闲字节和 142MB 直到 OOM
Image compression exception; Failed to allocate a 629749908 byte allocation with 16777216 free bytes and 142MB until OOM
我的应用程序中的图像大小有一些问题,所以我决定压缩图像,但出现异常 "Failed to allocate a 629749908 byte allocation with 16777216 free bytes and 142MB until OOM"。我知道这是一个内存问题,但是,我能做什么?还有其他选择吗?
这是我正在使用的方法
private Bitmap checkCompression(Bitmap imageTarget) {
double width = imageTarget.getWidth();//This has 2448
double height = imageTarget.getHeight();//This has 3264
double current = width * height;//Result is 7990272
int reference = 1800000;
double percentage = 0;
if (current > reference) {
percentage = current / reference;
return Bitmap.createScaledBitmap(imageTarget, (int) (width * percentage), (int) (height * percentage), true);
}
return imageTarget;
}
您应该尝试使用 picasso。它有一个非常好的方式来处理图像,尤其是大图像。看看here .
我的应用程序中的图像大小有一些问题,所以我决定压缩图像,但出现异常 "Failed to allocate a 629749908 byte allocation with 16777216 free bytes and 142MB until OOM"。我知道这是一个内存问题,但是,我能做什么?还有其他选择吗?
这是我正在使用的方法
private Bitmap checkCompression(Bitmap imageTarget) {
double width = imageTarget.getWidth();//This has 2448
double height = imageTarget.getHeight();//This has 3264
double current = width * height;//Result is 7990272
int reference = 1800000;
double percentage = 0;
if (current > reference) {
percentage = current / reference;
return Bitmap.createScaledBitmap(imageTarget, (int) (width * percentage), (int) (height * percentage), true);
}
return imageTarget;
}
您应该尝试使用 picasso。它有一个非常好的方式来处理图像,尤其是大图像。看看here .