这是你如何使用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
您的位图。
下面是谷歌文档:http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
您可以在清单中加入android:largeHeap="true"
增加分配给您的应用程序内存。
注意:增加heap
为您的应用程序不认为是一个理想的解决方案。
下面是从谷歌的提取物,解释它,
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.
这里的文档https://developer.android.com/training/articles/memory.html
使用'BitmapFactory.Options'对象作为第二个参数'decodeFile()'的完整链接。将'BitmapFactory.Options'中的'inSampleSize'设置为一个值,以使您接近所需的缩放大小。 – CommonsWare
您的操作需要比免费更多的内存。你对我们期望什么样的解决方案/帮助? – anderas
@ CommonsWare请举例说明如何使用BitmapFactory.Options? – nag