简体   繁体   中英

How to convert String to Uri which is taken from sqlite and set it in ImageView?

I was saving image Uri to SQLite as String which I picked from gallery and it was set as image to my ImageView. But from 2nd activity I'm taking the Image(Uri) as String and converting to Uri and setting to ImageView.

When I run the 2nd activity it is giving an error like

resolveUri failed on bad bitmap uri: content://com.miui.gallery.open/raw/06.jpg

The code is like.

String valueImage;

imageView.setImageURI(Uri.parse(valueImage));

Do I need to convert in another way?

Thank you.

You can use Glide . It's very easy and takes only one line.

String valueImage; // Get url fro SQLite

Glide
     .With(this)
     .Load(Uri.parse(valueImage))
     .Apply(RequestOptions.CircleCropTransform()).Into(imageView);

The import statement is to put into the app module gradle file (app/build.gradle)

implementation 'com.github.bumptech.glide:glide:4.9.0'

Hope it helps !

Try Glide for your requirement

Import glide using gradle

implementation 'com.github.bumptech.glide:glide:4.8.0'

Then set image to imageview using this method

Glide.with(context)
                .load(Uri.fromFile(new File(valueImage)))
                .into(imageView);

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