public class CashSoft {
//bitmap对象用软引用保存
private Map<String,SoftReference<Bitmap>> imageCash = new HashMap<String,SoftReference<Bitmap>>();

public void addBitmapToCash(String path){
Bitmap bitmap = BitmapFactory.decodeFile(path);
SoftReference<Bitmap> softReference = new SoftReference<>(bitmap);
imageCash.put(path,softReference);

}
public Bitmap getBitmapFormCash(String path){

SoftReference<Bitmap> softBitmap = imageCash.get(path);
if (softBitmap == null){
return null;
}
Bitmap bitmap = softBitmap.get();
return bitmap;
}

}

posted on 2017-09-22 11:59  跳动的米  阅读(98)  评论(0编辑  收藏  举报