我想在上传到服务器之前压缩图片,压缩后它将小于150kb,我已经做了here,问题是当图片大小超过6M,它发生了oom。我怎样才能避免oom!
发布于 2015-08-11 16:27:01
您链接的代码没有正确处理位图,您必须回收它们。当Android系统处理位图时,它会正确地回收它们,但无论何时您自己处理它,您都必须正确地将资源返回给系统。
请仔细阅读此https://developer.android.com/training/displaying-bitmaps/manage-memory.html,并应用所解释的观点
发布于 2015-08-11 17:37:40
参数ImageFile,你想要调整大小,高度和宽度的图像,你想在输出。
public static Bitmap Shrinkmethod(字符串文件,int width,int height) {
BitmapFactory.Options bitopt = new BitmapFactory.Options();
bitopt.inJustDecodeBounds = true;
Bitmap bit = BitmapFactory.decodeFile(file, bitopt);
int h = (int) Math.ceil(bitopt.outHeight / (float) height);
int w = (int) Math.ceil(bitopt.outWidth / (float) width);
if (h > 1 || w > 1) {
if (h > w) {
bitopt.inSampleSize = h;
} else {
bitopt.inSampleSize = w;
}
}
bitopt.inJustDecodeBounds = false;
bit = BitmapFactory.decodeFile(file, bitopt);
return bit;
}
https://stackoverflow.com/questions/31936129
复制相似问题