赞
踩
这是你如何使用BitmapFactory.Options:
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
options.inSampleSize = 2;
options.inJustDecodeBounds = false;
options.inTempStorage = new byte[16 * 1024];
Bitmap bmp = BitmapFactory.decodeFile(picturePath,options);
Bitmap resizedBitmap = Bitmap.createScaledBitmap(bmp, 960, 730, false);
您还可以通过编写自定义函数来计算位图的inSampleSize.
您可以通过在清单中添加android:largeHeap =“true”来增加分配给您的应用程序的内存.
注意:增加应用程序的堆不被认为是理想的解决方案.
以下是谷歌提取的解释,
However, the ability to request a large heap is intended only for a
small set of apps that can justify the need to consume more RAM (such
as a large photo editing app). Never request a large heap simply
because you’ve run out of memory and you need a quick fix—you should
use it only when you know exactly where all your memory is being
allocated and why it must be retained. Yet, even when you’re confident
your app can justify the large heap, you should avoid requesting it to
whatever extent possible. Using the extra memory will increasingly be
to the detriment of the overall user experience because garbage
collection will take longer and system performance may be slower when
task switching or performing other common operations.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。