80,362
社区成员
发帖
与我相关
我的任务
分享
File f = new File(locationUrl);
if (f.exists() && f.length() > 0) {
// 文件存在
BitmapFactory.Options bfOptions = new BitmapFactory.Options();
bfOptions.inDither = false;
bfOptions.inPurgeable = true;
bfOptions.inInputShareable = true;
bfOptions.inTempStorage = new byte[32 * 1024];
FileInputStream fs = null;
try {
fs = new FileInputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Bitmap bmp = null;
if (fs != null) {
try {
bmp = BitmapFactory.decodeFileDescriptor(fs.getFD(),null, bfOptions);
BitmapDrawable drawable = new BitmapDrawable(bmp);
imageCache.put(imageUrl, new SoftReference<Drawable>(drawable));
return drawable;
} catch (IOException e) {
e.printStackTrace();
}
}
}
Drawable cacheImage = 调用上面的代码得到的drawable
if (cacheImage != null) {
viewHolder.iv_img.setImageDrawable(cacheImage);
}