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;
file:///storage/emulated/0/cameratest/picture459838058.jpg
Remove file://
because the decodeFile() expects a file system path.
/storage/emulated/0/cameratest/picture459838058.jpg
Replace mImageUri.toString()
with mImageUri.getPath()
.
decodeFile
expects a path, not an uri string.
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.
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