读书人

将保留的文件读为bitmap

发布时间: 2012-06-27 14:20:09 作者: rapoo

将保存的文件读为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;

}

读书人网 >移动开发

热点推荐