I want to keep all the transformation, stoke and animations identical and was thinking if we can pass resource ID or asset name in Glide to load it locally?
Asked
Active
Viewed 5.7k times
3 Answers
175
For resource ids, you can use:
Glide.with(fragment)
.load(R.drawable.resource_id)
.into(imageView);
For assets, you can construct an asset uri:
Glide.with(fragment)
.load(Uri.parse("file:///android_asset/<assetName>"))
.into(imageView);

Sam Judd
- 7,317
- 1
- 38
- 38
-
11for "assetName" do not forget to add the extension, ex: "image.jpg" – Vitalie Suba May 17 '16 at 22:01
-
3Shouldn't it be `R.drawable.resource_id`? – Pedro Oliveira Nov 10 '17 at 15:32
-
6Might be obvious to others, but I spent a lot of time figuring this out because I thought `android_asset/assetName` should be replaced by my asset-path. Finally I found out it was only `assetName` and `file:///android_asset/` should always be present – Anigif Mar 05 '18 at 10:46
-
1Using with(fragment) is deprecated. Now you should use with(context) – Lorenzo Vincenzi Sep 20 '18 at 10:43
-
2Beware of `Uri.parse()` on modern android OS, instead go for `FileProvider.getUriForFile()` – iCantC Dec 03 '21 at 08:36
7
Glide
.with(context)
.load(uri)
.asBitmap()
.placeholder(R.drawable.yourimage)
.error(R.drawable.yourimage)
.into(yourview);
Apart from the above answer if the image URL return null you can load default image into the view as like above.

Boken
- 4,825
- 10
- 32
- 42

Senthilvel S
- 331
- 1
- 7
- 21
5
It works when using .asBitmap()
String pathUri="file:///android_asset/img/flower.jpg";
Glide.with(context).asBitmap().load(Uri.parse(pathUri)).into(holder.imgView_post);

Boken
- 4,825
- 10
- 32
- 42

Farhad Farzin
- 1,239
- 2
- 9
- 12