首页 > 解决方案 > 将带有过滤器的 SVG 转换为 Android Vector Drawable

问题描述

我需要转换包含过滤器标签的 SVG 文件,它通常由 fe* 标签组成。(feFloodfeGaussianBlur,...)Android Asset Studio 和其他工具无法处理它,我唯一想到的是在矢量可绘制中使用渐变,但它仅适用于 SVG 中的线性渐变。例如,Asset Studio 无法转换此代码

<svg width="230" height="120"
 xmlns="http://www.w3.org/2000/svg"
 xmlns:xlink="http://www.w3.org/1999/xlink">

 <filter id="blurMe">
    <feGaussianBlur in="SourceGraphic" stdDeviation="5" />
 </filter>

 <circle cx="60"  cy="60" r="50" fill="green" />

 <circle cx="170" cy="60" r="50" fill="green"
      filter="url(#blurMe)" />
</svg>

如果它是真实的,有人可以给出转换这些标签的算法吗?

标签: androidxmlsvg

解决方案


<filter>并且<feGuaussianBlur>是 SVG 过滤器元素。他们为 SVG 元素添加位图滤镜效果。

Android VectorDrawables does not support SVG filters.

如果您可以在没有滤镜效果(模糊)的情况下生活,请编辑您的 SVG 文件并删除它/它们。然后再次尝试导入。

如果您需要模糊效果,那么您将无法使用 aVectorDrawable.您将被迫使用位图图像。


推荐阅读