/** 异步加载头像位图到ImageLoader内存缓存 */ private static void asyncLoadAvatarBitmapToCache(UserInfoProvider.UserInfo userInfo) { if (userInfo == null || !isImageUriValid(userInfo.getAvatar())) { return; } String url = HeadImageView.getAvatarCacheKey(userInfo.getAvatar()); ImageLoader.getInstance() .loadImage( url, new ImageSize( HeadImageView.DEFAULT_AVATAR_THUMB_SIZE, HeadImageView.DEFAULT_AVATAR_THUMB_SIZE), avatarLoadOption, null); }
/** 从ImageLoader内存缓存中取出头像位图 */ private static Bitmap getMemoryCachedAvatarBitmap(UserInfoProvider.UserInfo userInfo) { if (userInfo == null || !isImageUriValid(userInfo.getAvatar())) { return null; } String key = HeadImageView.getAvatarCacheKey(userInfo.getAvatar()); // DiskCacheUtils.findInCache(uri, ImageLoader.getInstance().getDiskCache() 查询磁盘缓存示例 List<Bitmap> bitmaps = MemoryCacheUtils.findCachedBitmapsForImageUri( key, ImageLoader.getInstance().getMemoryCache()); if (bitmaps.size() > 0) { return bitmaps.get(0); } return null; }