0

Hey I've been having trouble retrieving a bitmap after I save it to a file. When I save the Bitmap:

try {
    FileOutputStream file = openFileOutput("my_file", MODE_PRIVATE);
    // bitmap defined elsewhere
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, file);
    file.close();
}
catch (Exception e) {
    e.printStackTrace();
}

When I try to open the file later, the image doesn't show up:

File file = new File("my_file");
imageView.setImageBitmap(BitmapFactory.decodeFile(file.getAbsolutePath()));

Would I need to use FileInputStream instead? Also will Bitmap.CompressFormat.PNG work on all image types? Any help is much appreciated.

  • "Also will Bitmap.CompressFormat.PNG work on all image types?" - A `Bitmap` is a `Bitmap`. There is no "type" until you write it to a file, so regardless of what image format you loaded the `Bitmap` from, you can save it as a PNG. – Mike M. Apr 17 '16 at 00:55
  • Thanks! The link helped me figure out the former problem (just ended up decoding an input stream) but thanks for giving me the heads up on the latter –  Apr 17 '16 at 01:05

0 Answers0