Reputation: 1081
I'm trying to get picture from filepath concerning the BitMapFactory.decodeFile for drawing bitmap in Canvas and get this exception:
Unable to decode stream: java.io.FileNotFoundException:
/content:/media/external/images/media/40: open failed: ENOENT (No such file
or directory)
02-02 10:03:19.793 3371-3371/com.group.digit.razvoj.appointment
E/AndroidRuntime: FATAL EXCEPTION: main
but when i use that filepath to setImage in Fragment it works fine.
Here is my code:
String urilogo = helper.getUri();
File imgFile = new File(urilogo);
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
In Fragment where it works:
String urilogo = helper.getUri();
if(urilogo!= null || urilogo!= "") {
imageView.setImageURI(Uri.parse(urilogo));
}
Upvotes: 1
Views: 5807
Reputation: 843
If you are not bothered about file name, you can use InputStream as:
InputStream is = getContentResolver().openInputStream(urilogo);
Bitmap bitmap = BitmapFactory.decodeStream(is);
is.close();
If above code doesn't work and helper.getUri()
is a file
Uri the use:
String urilogo = helper.getUri();
File imgFile = new File(new URI(urilogo));
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
Upvotes: 5