[英]How can I take a Drawable that I got from the internet and save it to my Android device in a cache directory?
[英]How do I put a File from my Cache directory in an ImageView on Android?
我使用以下代碼從Android設備上的目錄獲取JPG文件:
File f = new File(cacheDir, fn);
如何將f
放入ImageView中?
ImageView imgView = (ImageView)header.findViewById(R.id.imvCover);
// what call do I make here?
// this obviously is not correct and just for example.
imgView.setToFile(f);
嘗試這個。 由於您具有文件對象,請使用以下代碼。
這可能對您有幫助
Bitmap bmp = BitmapFactory.decodeFile(f.getAbsolutePath());
imgView.setImageBitmap(bmp);
我認為這是正確的,不是嗎?
Bitmap b = decodeFile(f);
imgView.setImageBitmap(b);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.