public class MemoryCacheUtils {
// HashMap<String, Bitmap> mMemoryCache = new HashMap<String, Bitmap>();
HashMap<String, SoftReference<Bitmap>> mMemoryCache = new HashMap<String, SoftReference<Bitmap>>();
public void setMemoryCache(String url,Bitmap bitmap){
// mMemoryCache.put(url, bitmap);
SoftReference<Bitmap> soft = new SoftReference<Bitmap>(bitmap);//使用软引用将bitmap包装起来
mMemoryCache.put(url, soft);
}
public Bitmap getMemoryCache(String url){
// mMemoryCache.get(url);
SoftReference<Bitmap> soft = mMemoryCache.get(url);
if(soft!=null){
Bitmap bitmap = soft.get();
return bitmap;
}
return null;
}
}
内存缓存
最新推荐文章于 2023-06-15 10:10:09 发布