简体   繁体   中英

From Bitmap to Uri - Android

In my Project I'm saving a given Bitmap to my phone's local gallery with the following method:

Bitmap bmp = some_fancy_bitmap;
imgeUrl = MediaStore.Images.Media.insertImage(getContentResolver(), bmp, "some Title", "some_Description");

MediaStore.Images.Media.insertImage gets the source Bitmap , saves it, and returns a String with the URL to the newly created image, or null if the image failed to be stored for any reason.

This is an example of imageUrl I am returned in case of successful saving: content://media/external/images/media/223 .

I'd now like to pass this Bitmap to a new Activity , in the form of the Uri of the resource.

How can I transform the imageUrl I was returned, or directly the Bitmap bmp, into the resource's Uri ?

Note: imageUrl is a String , and I want to get an Uri , not an URI .

Uri.parse(String url ) Creates a Uri which parses the given encoded URI string. Parameters: uriString an RFC 2396-compliant, encoded URI Returns: Uri for this given uri string Throws: NullPointerException - if uriString is null

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM