59

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?

JorgeAmVF
  • 1,392
  • 3
  • 14
  • 28
ir2pid
  • 3,650
  • 8
  • 40
  • 75

3 Answers3

157

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,017
  • 1
  • 33
  • 37
6
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
  • 3,207
  • 9
  • 25
  • 31
Senthilvel S
  • 311
  • 1
  • 7
  • 21
1

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
  • 3,207
  • 9
  • 25
  • 31
Farhad Farzin
  • 1,188
  • 2
  • 7
  • 12