private boolean getSavedPngAndSet(ImageView view, String logoUrl) {
String dir = this.getExternalCacheDir().getAbsolutePath();
File rootFileDir = new File(dir);
if(rootFileDir.exists() && rootFileDir.isDirectory()) {
String filename = logoUrl.replace("/", "").replace(":", "").replace(",", "")
.replace("\\", "").replace(".", "").replace("?", "").replace("|", "").replace("\"", "")
.replace(">", "").replace("<", "")+".png";
String[] mPngList = rootFileDir.list();
for(int i=0; i<mPngList.length; i++) {
if(StringUtils.IsShowLog) {
StringUtils.log(tag, "getSavePngList():mPngList[i]="+mPngList[i]);
}
if(mPngList[i].equals(filename)) {
try {
InputStream is = new BufferedInputStream(new FileInputStream(new File(dir+"/"+filename)));
Bitmap bitmap = BitmapFactory.decodeStream(is);
is.close();
view.setImageBitmap(bitmap);
getMyApplication().mUrlAndBitmap.put(logoUrl, bitmap);
if(StringUtils.IsShowLog) {
StringUtils.log(tag, "mPngList[i].equals(filename)="+mPngList[i].equals(filename));
}
return true;
}catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
}
return false;
}
本文介绍了一种从外部缓存目录加载PNG图片至ImageView的方法,并通过字符串处理确保文件名的唯一性。此外,还实现了将加载的Bitmap保存至应用程序缓存的功能。
1158

被折叠的 条评论
为什么被折叠?



