将 VectorDrawable 转换为 SVG

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

但我现在很难做相反的事。我有 VectorDrawable,但我不知道如何将其转换为 SVG,我可以找到零在线工具做到这一点。

有人有这方面的经验吗? 有什么步骤或工具可以做到这一点?

59039 次浏览

Steps I follow:

android:pathData replaced with d

android:fillColor replaced with fill

android:strokeColor replaced with stroke

android:strokeWidth replaced with stroke-width

android:fillType replaced with fill-rule

A path in the VectorDrawable without fillColor is fill="none" in SVG.

android:viewportHeight="24" android:viewportWidth="24" is viewBox="0 0 24 24" in SVG.

Example

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>

The VectorDrawable format is pretty similar to SVG.

You can find the documentation of the VectorDrawable format here, and the documentation of the SVG format here.

I just written this Python script which converts a vector drawable xml, to a svg. It doesn't cover all the vector drawable proprieties, but it works with the most common ones. You have only to drop your xml files onto the script, and the files will be converted.