2010-11-12 39 views
0

我想在我的imageview中顯示來自互聯網的圖像。位圖大小超過VM預算,同時從互聯網加載圖像?

這是提高以下錯誤的任何一個指導我我在這裏做什麼錯誤

公共位圖DisplayLiveImage(字符串ImageSrc) { 位圖BM; 嘗試{

       URL aURL = new URL(ImageSrc); 
          URLConnection conn = aURL.openConnection(); 

          conn.connect(); 
          InputStream is = null; 
          try 
          { 
           is= conn.getInputStream(); 
          }catch(IOException e) 
          { 
           return null; 
          } 

          BufferedInputStream bis = new BufferedInputStream(is); 

          bm = BitmapFactory.decodeStream(bis); 
          bis.close(); 
          is.close(); 

         } catch (IOException e) { 
          return null; 
         } 

         return bm; 

    } 

logcat的

11-12 21:45:22.509: ERROR/AndroidRuntime(7118): java.lang.OutOfMemoryError: bitmap size exceeds VM budget 
11-12 21:45:22.509: 

ERROR/AndroidRuntime(7118):  at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) 
11-12 21:45:22.509: 

ERROR/AndroidRuntime(7118):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:476) 
11-12 21:45:22.509: 

ERROR/AndroidRuntime(7118):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:537) 
11-12 21:45:22.509: 

ERROR/AndroidRuntime(7118):  at com.Finditnear.FindItNearActivityWithoutMenu.DisplayLiveImage 

(FindItNearActivityWithoutMenu.java:149) 
11-12 21:45:22.509: ERROR/AndroidRuntime(7118):  at com.Finditnear.ViewSingleImage$1.run 

(ViewSingleImage.java:88) 

任何幫助,將不勝感激。

回答

0

您嘗試加載的圖片有多大?如果它會導致一個大的位圖,你會用盡內存,因爲Android只會爲你的應用程序提供有限的內存(我認爲在2.2設備上爲16MB或24MB)。如果是大圖像檢出downsampling code on this post

相關問題