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 );
}
Solution 4:
Ok for me it was the file path was wrong so I needed to get the real filepath.
First
Filefile=newFile(getPath(uri));
public String getPath(Uri uri)
{
String[] projection = {MediaStore.Images.Media.DATA};
Cursorcursor= getContentResolver().query(uri,
projection,
null,
null,
null);
if (cursor == null)
returnnull;
intcolumn_index= cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
Strings= cursor.getString(column_index);
cursor.close();
return s;
}
Then Back To Uri
UrinewUri= 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"