将保存的文件读为bitmap

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;

}

你可能感兴趣的:(bitmap)