我正在尝试从图库中获取图像(按意图)。
我收到了这个错误:
985120-byte external allocation too large for this process.
Out of memory: Heap Size=4871KB, Allocated=2472KB, Bitmap Size=19677KB
VM won't let us allocate 985120 bytes
这是我获取图像的代码:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
....
mBitmap = Media.getBitmap(this.getContentResolver(), data.getData());
...
}
我该如何解决?
- - - - 更新 - - - - -
我注意到,如果我选择预先存在的图像(已安装 HTC 照片),我会收到此错误。如果我选择从相机中挑选的图像,一切正常。
所以,我根据这个http://developer.android.com/training/displaying-bitmaps/load-bitmap.html更改我的代码:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
InputStream stream = getContentResolver().openInputStream(data.getData());
mBitmap = BitmapFactory.decodeStream(stream,null,options);
stream.close();
但是现在位图是 NULL !!!