嗨,我从 URL 下载了一张图片,并将其作为位图写入文件。我正在尝试从文件中检索位图并显示它。有谁知道如何做到这一点?这是我尝试过的,它没有错误,但它不显示图像。
全球.java
public static void saveBitmapToFile(Context activityContext, Bitmap bitmap, String FileName){
try{
File file = new File(FileName);
FileOutputStream fOut = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 85, fOut);
fOut.flush();
fOut.close();}
catch (Exception e) {
e.printStackTrace();
Log.i(null, "Save file error!");
}
}
public static Bitmap returnBitmapFromFile(Context activityContext, String FileName){
Bitmap bitmap = BitmapFactory.decodeFile(FileName);
return bitmap;
}
GetBitmap.java
public void downloadUserPhoto(){
String userPhotoUrl = "http://static.bbci.co.uk/h4discoveryzone/ic/newsimg/media/images/229/129/68805000/jpg/_68805145_pahs2.jpg"
userPhoto = Global.createBitmapFromUrl(this, userPhotoUrl);
Global.saveBitmapToFile(this, userPhoto, "user_photo");
}
public void getUserPhoto(){
loadingText.setText("Getting User Pictures...");
Bitmap setUserPhoto = Global.returnBitmapFromFile(this, "user_photo");
logo.setImageBitmap(setUserPhoto);
}