Skip to content
Advertisement

Does Glide have a method for loading both PNG and SVG?

I’m using Glide to load some images asynchronously into some of my ImageViews, and I know it can handle images like PNG or JPG as it can handle SVG.

Thing is, As far as I know, the way I load those two kinds of image differs. Like:

Loading “normal” images

JavaScript

Loading SVG

JavaScript

And if I try to load SVG with the first method it won’t work. If I try to load PNG or JPG with the second method, it won’t work either.

Is there a generic way to load both image types using Glide?

The server where I’m fetching those images from don’t tell me the image type before I download it. It’s a REST server and the resource will be retrieved in a way like "http://foo.bar/resource". The only way to know the image type is reading the HEAD response.

Advertisement

Answer

You can use Glide & AndroidSVG together to achieve your goal.

There is sample from Glide for SVG.Sample Example

Setup RequestBuilder

JavaScript

Use RequestBuilder with uri

JavaScript

This way you can achieve your goal. I hope this is helpful.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement