通过字符串创建和显示SVG [英] Creating and displaying an SVG from a String

查看:516
本文介绍了通过字符串创建和显示SVG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表示svg的字符串.

I have a string that represents a svg.

<svg height="210" width="400"><path d="M150 0 L75 200 L225 200 Z" />

如何将该字符串转换为Drawable,Bitmap或类似名称以在imageview中显示?

How can I turn this string into a Drawable, Bitmap or similar to display it in an imageview?

推荐答案

您可以选择一些Android的SVG库.每个人的操作都会略有不同.

There are a few SVG libraries for Android you can choose. Each will do it slightly differently.

对于AndroidSVG,您可以这样做:

For AndroidSVG, you would do it like this:

SVG  svg = SVG.getFromString(myStringWithSvgInIt);
PictureDrawable  pd = new PictureDrawable(svg.renderToPicture());

myImageView.setImageDrawable(pd);

这篇关于通过字符串创建和显示SVG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆