将VectorDrawable转换为SVG

时间:2017-07-06 12:04:50

标签: android svg android-vectordrawable

我手动或使用网络工具进行了相反的转换(SVG到VectorDrawable)。

但我很难做相反的事情。我有VectorDrawable但我不确定如何将其转换为SVG,我可以找到零在线工具来完成它。

有没有人有这方面的经验,有哪些步骤或工具呢?

2 个答案:

答案 0 :(得分:73)

我遵循的步骤:

android:pathData已替换为d

android:fillColor已替换为fill

SVG中没有fillColor的VectorDrawable中的路径为fill="none"

SVG中{p> android:viewportHeight="24" android:viewportWidth="24"viewBox="0 0 24 24"

示例

Vector Drawable

<?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>

答案 1 :(得分:26)

VectorDrawable 格式非常类似于 SVG

您可以找到 VectorDrawable 格式here的文档,以及 SVG 格式here的文档。

我刚写了this Python script,它将矢量可绘制的xml转换为svg。 它并不涵盖所有矢量可绘制的属性,但它适用于最常见的。 您只需将xml文件放到脚本上,文件就会被转换。