2013-07-12 196 views
1

我開發一個Android應用程序,我這樣做是爲了保存一個位圖到內部存儲器中的圖像:顯示存儲在內部存儲

protected void onPostExecute(Bitmap profilePicture) 
    { 
     FileOutputStream fOut = null; 

     try 
     { 
      fOut = openFileOutput(Constants.FB_PROFILE_IMAGE_FILE_NAME, Context.MODE_PRIVATE); 
      profilePicture.compress(Bitmap.CompressFormat.JPEG, 85, fOut); 
      fOut.flush(); 
     } 
     catch (FileNotFoundException e) 
     { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     catch (IOException e) 
     { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     finally 
     { 
      try 
      { 
       fOut.close(); 
      } 
      catch (IOException e) 
      { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } 

     loadingDialog.dismiss(); 
    } 

我該怎麼做才能將它打開並顯示到ImageView

此代碼不起作用,因爲imgFile不存在:

private void loadAndShowUserProfileImage() 
{ 
    File imgFile = new File(Constants.FB_PROFILE_IMAGE_FILE_NAME); 
    if(imgFile.exists()) 
    { 
     Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); 

     userImageProfile.setImageBitmap(myBitmap); 
    } 
} 

回答

3
FileInputStream fIn = openFileInput(Constants.FB_PROFILE_IMAGE_FILE_NAME); 
Bitmap myBitmap = BitmapFactory.decodeStream(fIn); 

openFileOutput/openFileInput應該對總是使用

+0

遺憾的錯字 – Blackbelt