[問題] 關於網路設定圖片+快取

看板AndroidDev作者 (ENFJ)時間12年前 (2012/04/10 01:15), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/3 (看更多)
最近寫程式一直碰到OOM的困擾!! 有拜讀了一些文章,但是在實作網路讀取圖片加快取時似乎還是會把記憶體用光 我想做的是將網址上的圖片 "壓縮暫存" 下來 於是照著這篇文章下去做 http://julianshen.blogspot.com/2010/08/android-bitmapoutofmemoryerror.html InputStream input = connection.getInputStream(); BitmapFactory.Options option = new BitmapFactory.Options(); option.inJustDecodeBounds = true; BitmapFactory.decodeStream(input); Bitmap myBitmap = BitmapFactory.decodeStream(input, null, option); final int NEW_SIZE=100; int width=option.outWidth; int height=option.outHeight; int scale=1; while(true){ if(width/2<NEW_SIZE || height/2<NEW_SIZE) break; width/=2; height/=2; scale++; } //因為要做兩次,所以又讓INPUT進來一次 connection.setDoInput(true); BitmapFactory.Options option_ = new BitmapFactory.Options(); option_.inSampleSize=scale; Bitmap myBitmap = BitmapFactory.decodeStream(input, null, option_); input.close(); return myBitmap; 但是我並沒有得到壓縮的圖片 也沒有任何圖片顯示出來,而且要跳轉到下一頁滿是圖片的activity時 依然還是會OOM 能不能請板上大大提供大量讀取網路圖片又不會oom的寫法呢? 感激不盡 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.115.158.190

04/10 01:32, , 1F
FACTORY always return null
04/10 01:32, 1F
文章代碼(AID): #1FWnajSX (AndroidDev)
文章代碼(AID): #1FWnajSX (AndroidDev)