作者sorrel20567 (ENFJ)
看板AndroidDev
标题[问题] 关於网路设定图片+快取
时间Tue Apr 10 01:15:23 2012
最近写程式一直碰到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
1F:→ sorrel20567:FACTORY always return null 04/10 01:32