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;
}
}