public Bitmap getBitmap(String url) { // 从内存缓存中获取图片 Bitmap result = memoryCache.getBitmapFromCache(url); if (result == null) { // 文件缓存中获取 result = fileCache.getImage(url); if (result == null) { // 从网络获取 result = getBitmapFromWeb(url); if (result != null) { fileCache.saveBitmap(result, url); memoryCache.addBitmapToCache(url, result); System.out.println("图片从网络中获取"); } } else { // 添加到内存缓存 memoryCache.addBitmapToCache(url, result); System.out.println("图片从文件缓存中获取"); } } else { System.out.println("图片从内存缓存中获取"); } return result; } // end getBitmap
/** * get one image from three places, imageMemoryCache,imageFileCache,network * * @param url The URL of the image to download. * @return Bitmap return a bitmap */ private Bitmap getBitmap(final String url) { if (null == url || "".equals(url)) { return null; } // get image from mLruMemoryCache Bitmap result = null; result = mLruMemoryCache.get(url); if (result == null) { // get image from imageFileCache result = imageFileCache.getImage(url); if (result == null) { // get image from network // result = getImageHttp(url); result = getImageFromHttp(url); if (result != null) { if (mLruMemoryCache.get(url) == null) { mLruMemoryCache.put(url, result); } imageFileCache.addImgToSDTask(url, result); } } else { if (mLruMemoryCache.get(url) == null) { mLruMemoryCache.put(url, result); } } } return result; }
public Bitmap getBitmap(String url) { String filename = FileUtil.convertUrlToFileName(url); boolean isDownload = true; if (url.startsWith("http") || url.toLowerCase().startsWith("http")) { url = filename; } else { isDownload = false; } Bitmap result = memoryCache.getBitmapFromCache(filename); if (result == null && fileCache != null) { result = fileCache.getImage(url, isDownload); if (result != null) { memoryCache.addBitmapToCache(filename, result); } } return result; }