我正在开发一个 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);
}
}