【发布时间】:2017-12-10 10:20:27
【问题描述】:
我已经手动或使用网络工具进行了相反的转换(SVG 到 VectorDrawable)。
但我很难做相反的事情。我有VectorDrawable,但我不确定如何将其转换为 SVG,我可以找到零个在线工具来做到这一点。
有没有人有这方面的经验,有哪些步骤或工具可以做到这一点?
【问题讨论】:
标签: android svg android-vectordrawable
我已经手动或使用网络工具进行了相反的转换(SVG 到 VectorDrawable)。
但我很难做相反的事情。我有VectorDrawable,但我不确定如何将其转换为 SVG,我可以找到零个在线工具来做到这一点。
有没有人有这方面的经验,有哪些步骤或工具可以做到这一点?
【问题讨论】:
标签: android svg android-vectordrawable
我遵循的步骤:
android:pathData 替换为d
android:fillColor 替换为fill
android:strokeColor 替换为stroke
android:strokeWidth 替换为stroke-width
android:fillType 替换为fill-rule
VectorDrawable 中没有fillColor 的路径是SVG 中的fill="none"。
android:viewportHeight="24" android:viewportWidth="24" 在 SVG 中是 viewBox="0 0 24 24"。
示例
矢量绘图
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="#ffffff"
android:pathData="M12,3L2,12h3v8h2.5v-0.8c0-1.5,3-2.2,4.5-2.2s4.5,0.8,4.5,2.2V20H19v-8h3L12,3zM12,15.2c1.2,0-2.2-1-2.2-2.2 s1-2.2,2.2-2.2s2.2,1,2.2,2.2S13.2,15.2,12,15.2z" />
<path android:pathData="M0,0h24v24H0V0z" />
</vector>
SVG
<svg xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24" >
<path
fill="#ffffff"
d="M12,3L2,12h3v8h2.5v-0.8c0-1.5,3-2.2,4.5-2.2s4.5,0.8,4.5,2.2V20H19v8h3L12,3zM12,15.2c1.2,0-2.2-1-2.2-2.2 s1-2.2,2.2-2.2s2.2,1,2.2,2.2S13.2,15.2,12,15.2z" />
<path d="M0,0h24v24H0V0z" fill="none"/>
</svg>
【讨论】:
VectorDrawable 格式与 SVG 非常相似。
您可以找到VectorDrawable格式的文档here,以及SVG格式的文档here。
我刚刚写了this Python script,它将矢量可绘制xml 转换为svg。 它没有涵盖所有矢量可绘制属性,但它适用于最常见的属性。 您只需将 xml 文件拖放到脚本中,文件就会被转换。
【讨论】:
pip install xml
Exec=python /opt/utils/xml2svg.py %U 创建桌面快捷方式现在我可以将文件拖放到桌面快捷方式上:) 我还编辑了两件事:现在脚本在转换后删除源xml文件,现在没有@987654327的svg文件名@预扩展。