2012-05-05 34 views
-3

我採取與相機的圖像的儲存於SD卡,存儲必須從SD卡上傳圖像到ImageView的那樣:java.lang.OutOfMemoryError

myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); 
ImageView _image=(ImageView)view.findViewById(R.id.imageCarte); 
_image.setImageBitmap(myBitmap); 

,但我有此錯誤:

05-05 08:23:20.593: E/AndroidRuntime(1936): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget.

任何人都可以幫助我。謝謝

+0

比例位圖之前的圖像大小,你嘗試將其設置爲ImageView的面前,因爲錯誤說: – BeRecursive

+1

因爲我已經說過(昨天)類似的問題被張貼至少是在目前過大每天兩次。在發佈之前請先檢查相關問題。答案基本上指向這裏:http://developer.android.com/training/displaying-bitmaps/index.html –

+0

[java.lang.OutOfMemoryError:位圖大小超過VM預算的可能的重複 - Android](http:/ /stackoverflow.com/questions/1949066/java-lang-outofmemoryerror-bitmap-size-exceeds-vm-budget-android) –

回答

0

在手機中使用BitmapFactory是一個消耗內存的過程。當您嘗試連續解碼大量圖像時,會出現此問題。 和java一樣,沒有選項可以釋放分配給變量「myBitmap」的內存。因此,確保在使用它們後將這些類型的變量設置爲空。

另外嘗試使用

System.gc() to clear the garbage collection. 

如果錯誤在執行拋出 「_image.setImageBitmap(MYBITMAP);」行,然後儘量減少顯示

相關問題