Fresco: How to load images from Resources(R.drawable.image)?

Created on 9 Apr 2015  路  8Comments  路  Source: facebook/fresco

I'm trying to load a resource image called "R.drawable.rating_golden_crown" in a SimpleDraweeView.
But how to translate this into a Fresco supported URI?

Most helpful comment

Uri.parse("res:///" + R.drawable.rating_golden_crown) works for me. I think they need to make the URI syntax for resources/assets clearer.

All 8 comments

Uri.parse("res:///" + R.drawable.rating_golden_crown) works for me. I think they need to make the URI syntax for resources/assets clearer.

Pull request #53 should take care of this. Stay tuned.

Thanks, I've used GenericDraweeHierarchy.setBackground to solve the problem temporarily. Will try the "res:///" tomorrow. I thought it's only two "/".

it's really three "/". two "/" not work :)

Uri uri = new Uri.Builder()
.scheme(UriUtil.LOCAL_RESOURCE_SCHEME) // "res"
.path(String.valueOf(resId))
.build();
// uri looks like res:/123456789
simpleDraweeView.setImageURI(uri);

http://stackoverflow.com/questions/30887615/loading-drawable-image-resource-in-frescos-simpledraweeview
this works for me

The URI thing kinda works, but because the URI is exactly the same for all configuration, the caching will screw things up if you want different images for different languages or orientations. Can we have actual built in support for this @tyronen?

"res:///" +R.drawable.xxx is working

Regarding the use of res///, a suggestion would be to enable the normal use of R.drawable, and hide away the ///res. That solution gives me as a programmer nothing but a tint of extra complexity. What do you say?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eldk picture eldk  路  3Comments

stephen-workpop picture stephen-workpop  路  4Comments

goodev picture goodev  路  4Comments

liubaoyua picture liubaoyua  路  3Comments

rhettor picture rhettor  路  3Comments