使用软引用SoftReference 内存缓存

it2026-02-11  13

1 2 // 第一中缓存图片的方式 通过内存来缓存      Map<String, SoftReference<Bitmap>> iconCache; 1 2 // 初始化内存缓存          iconCache = new HashMap<String, SoftReference<Bitmap>>(); 1 2 3 4 5 6 7 8 9 10 11 // 以下第一种加载图片的方式                 /*               * if (iconCache.containsKey(imagePath)) { SoftReference<Bitmap>               * reference = iconCache.get(imagePath); if (reference != null) {               * Bitmap bitmap = reference.get(); book_img.setImageBitmap(bitmap);               *                * } else { loadingImage(imagePath); }               *                * } else { loadingImage(imagePath); }               */ 1 2 3 4 /*                               * // 加载图片到内存中 iconCache.put(imagePath, new                               * SoftReference<Bitmap>( bitmap));                               */

 

 

 

 

 

 

 

 

 

来自为知笔记(Wiz)

转载于:https://www.cnblogs.com/feelbest/p/3696193.html

相关资源:数据结构—成绩单生成器
最新回复(0)