Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Picasso load drawable resources from their URI

I have to show a drawable from res into an ImageView. In this app, I'm using Picasso for some reasons.

In this case, I need to load the drawable using its URI and not its id. To do that, here is my code:

uri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://"+context.getPackageName()+"/drawable/" + drawableName); 

where drawableName used here are file names rather than their resource ids.

Then

Picasso.with(context).load(uri).into(imageView); 

I know for sure that drawable name is correct, but Picasso seems it does not like this uri.

like image 554
Daniele Vitali Avatar asked Jan 16 '14 09:01

Daniele Vitali


People also ask

How do I get URI from drawable?

You should use ContentResolver to open resource URIs: Uri uri = Uri. parse("android. resource://your.package.here/drawable/image_name"); InputStream stream = getContentResolver().

How will you load an image into an imageView from an image URL using Picasso?

Image loading using Picasso is very easy, you can do it like this way Picasso. get(). load("http://i.imgur.com/DvpvklR.png").into(imageView); and in their website you can get every details. In your case you can parse every image URL and use RecyclerView to show them along with Picasso.


2 Answers

If the images is in your drawable folder then you can just load it.

Picasso.with(context).load(R.drawable.drawableName).into(imageView); 

and picasso will load it no need for an Uri.

like image 167
Aegis Avatar answered Oct 22 '22 15:10

Aegis


Found the answer. Unfortunately, Picasso do not allow drawable loading via URI. It is an incoming feature.

like image 23
Daniele Vitali Avatar answered Oct 22 '22 17:10

Daniele Vitali