Skip to content Skip to sidebar Skip to footer

BitmapFactory: Unable To Decode Stream: Java.io.FileNotFoundException Even When File IS Actually There

I'm creating a simple app to take a picture. this is my code Button b1; ImageView iv; String TAG = 'MAIN ACTIVITY'; File photo; private Uri mImageUri; private File createTempora

Solution 1:

Replace mImageUri.toString() with mImageUri.getPath().

decodeFile expects a path, not an uri string.


Solution 2:

file:///storage/emulated/0/cameratest/picture459838058.jpg

Remove file:// because the decodeFile() expects a file system path.

/storage/emulated/0/cameratest/picture459838058.jpg

Solution 3:

Use BitmapFactory.decodeStream instead of BitmapFactory.decodeFile.

try ( InputStream is = new URL( file_url ).openStream() ) {
  Bitmap bitmap = BitmapFactory.decodeStream( is );
}

Source https://stackoverflow.com/a/28395036/5714364


Solution 4:

Ok for me it was the file path was wrong so I needed to get the real filepath.

First

File file = new File(getPath(uri));

public String getPath (Uri uri)
{
    String[] projection = {MediaStore.Images.Media.DATA};
    Cursor cursor = getContentResolver().query(uri,
                                               projection,
                                               null,
                                               null,
                                               null);
    if (cursor == null)
        return null;
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    String s = cursor.getString(column_index);
    cursor.close();
    return s;
}

Then Back To Uri

Uri newUri = Uri.fromFile(file);

This conversion to file and back to uri did the trick for me. I was receiving simple data from action.SEND.


Post a Comment for "BitmapFactory: Unable To Decode Stream: Java.io.FileNotFoundException Even When File IS Actually There"