我從url加載圖像。它沒問題,但是當很長一段時間它錯誤outofmemory:位圖大小超過vm預算。這裏我的代碼從URL加載圖像到位圖時的OutOfMemory
BitmapFactory.Options bmOptions;
bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
//from web
try {
Bitmap bitmap=null;
InputStream is=new URL(url).openStream();
BitmapFactory.decodeStream(is, null, bmOptions);
is.close();
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = 1;
is = new URL(url).openStream();
bitmap = BitmapFactory.decodeStream(is, null, o2);
is.close();
return bitmap;
} catch (Exception ex){
ex.printStackTrace();
return null;
}
請幫助我!
哪條線會出錯? – user496854 2011-06-03 07:15:33
圖像有多大?檢查出這個問題以及http://stackoverflow.com/questions/2928002/outofmemoryerror-bitmap-size-exceeds-vm-budget-android – 2011-06-03 07:17:36
我加載大圖像 – 2011-06-03 08:22:02