在我的應用程序中,我從URL中獲取4-5位圖並將它們用作圖庫。位圖大小超過虛擬機預算VS使用可繪製android
如果我切換圖像超過6-10倍我得到這個錯誤:
09-01 12:08:45.217: E/AndroidRuntime(350): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
09-01 12:08:45.217: E/AndroidRuntime(350): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
09-01 12:08:45.217: E/AndroidRuntime(350): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:459)
09-01 12:08:45.217: E/AndroidRuntime(350): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:515)
這是我的代碼:
try {
bitmapResult = BitmapFactory.decodeStream((InputStream)new URL(url[newPage+1]).getContent());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
v.setImageBitmap(bitmapResult);
我的問題OS這樣的:
請問這個只發生在模擬器中?
更多,更重要。如果使用drawable insted,會更高效嗎?在這種情況下,我會將我的位圖轉換爲可繪製的代碼,我將setImageresource。我必須「釋放」任何東西嗎?
Drawable d = new BitmapDrawable(getResources(),bitmapResult);
一個'BitmapDrawable'只是包裝一個'Bitmap'所以它使用相同的內存量。 – zapl