我有一個大的內存問題:的OutOfMemoryError:Android的大位圖的旋轉(90°)
// in sourceImage is a big JPEG previously loaded
Matrix mat = new Matrix();
mat.postRotate(90);
Bitmap rotatedImage = Bitmap.createBitmap(sourceImage, 0, 0, sourceImage.getWidth(), sourceImage.getHeight(), mat, true);
我總是運行這段代碼,我的應用程序崩潰,並且說「VM不會讓我們分配XXXXXX字節」
你能幫我嗎?
編輯:
我看到很多類似的問題在這裏,但我不知道如何rotatating之前回收sourceImage ......(導致二審是大的同時保持它)
謝謝。
如果你的源圖像很大,它已經消耗了太多的可用內存。在此操作之後,您將圖像在內存中保存兩次('sourceImage'和旋轉後的版本'rotatedImage')。這可能太多了。請在這個網站上搜索「OutOfMemoryException」,這個問題已經被多次詢問和回答。 – 2011-11-21 13:10:25
感謝您的評論,是的,我在這裏看到很多類似的問題,但我想知道如何在RAM中不保存兩個位圖實例的情況下做到這一點。 – Lyra