Search code examples
androidbitmapfileinputstreambitmapfactory

BitmapFactory.decodeStream(fileInputStream) returns null - Android


I have a problem with the following code in Android Studio:

try {
     FileInputStream fileInputStream = new FileInputStream(dirPhoto);
     bitmap = BitmapFactory.decodeStream(fileInputStream);
     vwImagen.setImageBitmap(bitmap);
} catch (SecurityException io) {

} catch (FileNotFoundException io) {

}

The fileInputStream was found, but method BitmapFactory.decodeStream(fileInputStream) return a null.

dirPhoto=/data/data/com.example.leandro.application/files/pic_20170316104409.jpg

Solution

  • The problem was that for some reason FileInputStream could not decode the address contained in dirPhoto (even if it existed). I solved it by creating the address with the method: "myContext.getExternalFilesDir(Environment.DIRECTORY_PICTURE‌​S).getAbsolutePath()‌​"

    Thank you very much!