Share via


resolveUri failed on bad bitmap uri

Question

Thursday, July 31, 2014 8:26 PM

Hi,

I have an issue that I can't figure out.

I am displaying images in my app that are either chosen from the gallery or a new image taken with the camera and then displayed.

In either case, it works great displaying the image.

From Gallery - using data.Data as the Uri and displaying in an ImageView using SetImageUri From Camera - using Uri.FromFile and displaying in an ImageView

Here is the rub.

The images are created/chosen by the user and saved to a database. I put the Uri.ToString() value in the tag of the ImageVIew and when the user clicks the Save button, I save the Uri strings in the database. The Uris look like this: content://com.android.providers.media.documents/document/image%3A12

Now, if the user goes back to edit the same record again, I pull the Uri strings out of the database and display them in ImageViews. However, no matter what I have tried, I can't get the images to load with the above Uri format. I have also tried to get the real file path from the image with a Content Resolver but that is not working either. Per Google searching, it looks like this is no longer possible as of API 19.

I usually get the following exception: resolveUri failed on bad bitmap uri: content://com.android.providers.media.documents/document/image%3A12

Interestingly: When the image comes in from the gallery, it has that exact Uri and loads fine.

I must be missing something simple.

My question is: How do I get a Bitmap or ImageView to display the image given the Uri format above?

Any help is appreciated!

All replies (1)

Tuesday, August 5, 2014 10:38 AM

@ScottButler? try to this way :

Set uri in bitmap image .

Uri uri = data.Data; 
Bitmap bmp=BitmapFactory.DecodeStream(ContentResolver.OpenInputStream(uri));
imgProfileIcon.SetImageBitmap (bmp);