【发布时间】:2012-08-27 18:34:09
【问题描述】:
我正在尝试从图库中获取图片(按意图)。
我收到了这个错误:
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 !!!
【问题讨论】:
-
options.inJustDecodeBounds = true;有了这个,你只解码位图的大小,而不是分配它,所以这就是它为空的原因。尝试使用 options.inScale 来减小位图的大小。
标签: android bitmap out-of-memory