這是你如何使用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