Reputation: 45911
I'm developing an Android application and I do this to save a bitmap into internal storage:
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();
}
How can I do to open it and show it into an ImageView
?
This code doesn't work because imgFile
doesn't exist:
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);
}
}
Upvotes: 1
Views: 74
Reputation: 157447
FileInputStream fIn = openFileInput(Constants.FB_PROFILE_IMAGE_FILE_NAME);
Bitmap myBitmap = BitmapFactory.decodeStream(fIn);
openFileOutput/openFileInput
should be always used in pair
Upvotes: 3