Skip to content
Advertisement

How do I load SVG String into ImageView

I have an SVG string

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 60 30" width="1200" height="600"><clipPath id="a"><path d="M30 15h30v15zv15h-30zh-30v-15zv-15h30z"/></clipPath><path d="M0 0v30h60v-30z" fill="#00247d"/><path d="M0 0l60 30m0-30l-60 30" stroke="#fff" stroke-width="6"/><path d="M0 0l60 30m0-30l-60 30" clip-path="url(#a)" stroke="#cf142b" stroke-width="4"/><path d="M30 0v30m-30-15h60" stroke="#fff" stroke-width="10"/><path d="M30 0v30m-30-15h60" stroke="#cf142b" stroke-width="6"/></svg>

How do I render it on ImageView?

If this was .svg file, I can load it with Glide in Android or other SVG library but don’t know how to get around it with this svg string.

Advertisement

Answer

Try this out I think this may help you.let me know if this works

 String yourSvgFile = "Your svg file";
        InputStream stream = new ByteArrayInputStream(yourSvgFile.getBytes(StandardCharsets.UTF_8));
        Glide.with(this).load(stream).into(yourView)
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement