Android |获取和压缩位图的正确方法内存不足

时间:2016-04-12 20:54:52

标签: android bitmap out-of-memory

在我的应用中,我得到了一个图像(位图):

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select"), GET_CODE);

然后,在onActivityResult中,我从uri获取位图,其中包含:

Uri uri = data.getData();
Bitmap bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), uri); //here I've the error

对于大图像,我收到错误

Caused by: java.lang.OutOfMemoryError: Failed to allocate a 268435468 byte allocation with 16777216 free bytes and 167MB until OOM

如何正确压缩位图?

0 个答案:

没有答案