简体   繁体   English

为什么 Android Asset Studio 会剪切我的矢量图像?

[英]Why does Android Asset Studio cut my vector images?

In my app, I am using this image: https://pixabay.com/sv/plus-l%C3%A4gga-till-%C3%B6ka-ikon-knappen-1270001/在我的应用程序中,我使用这个图像: https : //pixabay.com/sv/plus-l%C3%A4gga-till-%C3%B6ka-ikon-knappen-1270001/

However, when I try to import it as a Vector Asset in Android Studio, the Asset Studio cuts it in the left and right edges so that it's not a full circle anymore.但是,当我尝试在 Android Studio 中将其作为 Vector Asset 导入时,Asset Studio 会在左右边缘对其进行切割,使其不再是一个完整的圆形。 Why does this happen?为什么会发生这种情况? How can I fix it?我该如何解决? Do I have to modify the svg, or can I change some setting in Android Studio?我必须修改 svg,还是可以更改 Android Studio 中的某些设置?

For me, it looks like对我来说,它看起来像这个

Here is the XML code of the SVG:这是 SVG 的 XML 代码:

<?xml version="1.0" encoding="UTF-8"?>
<svg version="1.1" viewBox="0 0 35.876 35.876" xmlns="http://www.w3.org/2000/svg">
 <g transform="translate(-1.5317 -1015.4)">
  <circle transform="matrix(-.5 -.86603 .86603 -.5 0 0)" cx="-904.64" cy="-499.82" r="16.205" fill="none" stroke="#ff5e00" stroke-width="3.4773"/>
  <flowRoot fill="#000000" font-family="Sans" font-size="46.364px" letter-spacing="0px" word-spacing="0px" style="line-height:125%" xml:space="preserve"><flowRegion><rect x="-3.0977" y="-173.71" width="144.82" height="50.201"/></flowRegion><flowPara/></flowRoot>
  <rect transform="rotate(90)" x="1032" y="-27.666" width="2.7808" height="16.392" rx=".20089" ry=".20089" fill="#ff5e00"/>
 </g>
</svg>

And here is what the XML looks like of the Vector Drawable:这是 Vector Drawable 的 XML 样子:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="35dp"
        android:height="35dp"
        android:viewportWidth="35.876"
        android:viewportHeight="35.876">
    <path
        android:pathData="M17.93,17.96m8.1,14.03a16.21,16.21 83.34,1 1,-16.2 -28.07a16.21,16.21 83.34,1 1,16.2 28.07"
        android:strokeColor="#ff5e00"
        android:fillColor="#00000000"
        android:strokeWidth="3.4773"/>
    <path
        android:fillColor="#FF000000"
        android:pathData="M-3.99,-1020.96h124.94v43.31h-124.94z"/>
    <path
        android:pathData="M16.75,9.8L19.13,9.8A0.2,0.2 0,0 1,19.33 10L19.33,25.99A0.2,0.2 0,0 1,19.13 26.19L16.75,26.19A0.2,0.2 0,0 1,16.55 25.99L16.55,10A0.2,0.2 0,0 1,16.75 9.8z"
        android:fillColor="#ff5e00"/>
    <path
        android:pathData="M26.13,16.8L26.13,19.18A0.2,0.2 101.89,0 1,25.93 19.38L9.94,19.38A0.2,0.2 102.72,0 1,9.74 19.18L9.74,16.8A0.2,0.2 102.72,0 1,9.94 16.6L25.93,16.6A0.2,0.2 101.89,0 1,26.13 16.8z"
        android:fillColor="#ff5e00"/>
</vector>

This seems to be due to a bug in the Android Studio SVG import feature.这似乎是由于 Android Studio SVG 导入功能中的错误。 It is not converting that <circle> element in the SVG properly.它没有正确转换 SVG 中的<circle>元素。

Check out the example below.看看下面的例子。 The original elements from the SVG are in green.来自 SVG 的原始元素是绿色的。 I've converted the path elements from the VectorDrawable back to SVG paths and overlaid them on the original SVG.我已将 VectorDrawable 中的路径元素转换回 SVG 路径,并将它们覆盖在原始 SVG 上。 You can see that the circle path in red (from the VectorDrawable) doesn't match the original SVG.您可以看到红色的圆形路径(来自 VectorDrawable)与原始 SVG 不匹配。

 <svg version="1.1" viewBox="0 0 35.876 35.876" xmlns="http://www.w3.org/2000/svg"> <g transform="translate(-1.5317 -1015.4)"> <circle transform="matrix(-.5 -.86603 .86603 -.5 0 0)" cx="-904.64" cy="-499.82" r="16.205" fill="none" stroke="#00ff00" stroke-width="3.4773"/> <rect transform="rotate(90)" x="1032" y="-27.666" width="2.7808" height="16.392" rx=".20089" ry=".20089" fill="#00ff00"/> </g> <g id="converted back from VectorDrawable"> <path d="M17.93,17.96m8.1,14.03a16.21,16.21 83.34,1 1,-16.2 -28.07a16.21,16.21 83.34,1 1,16.2 28.07" fill="none" stroke="red" stroke-width="3.4773" stroke-opacity="0.3"/> <path d="M26.13,16.8L26.13,19.18A0.2,0.2 101.89,0 1,25.93 19.38L9.94,19.38A0.2,0.2 102.72,0 1,9.74 19.18L9.74,16.8A0.2,0.2 102.72,0 1,9.94 16.6L25.93,16.6A0.2,0.2 101.89,0 1,26.13 16.8z" fill="red" fill-opacity="0.5"/> </g> </svg>

The fault is possibly exacerbated by the fact that the original SVG icon has been messily designed.原来的SVG图标设计混乱,可能会加剧这个错误。 It is full of coordinates with odd decimals and weird transforms.它充满了奇数小数和奇怪变换的坐标。

I could fix the SVG for you, but I imagine you have multiple icons that possibly exhibit the same fault.我可以为您修复 SVG,但我想您有多个图标可能会出现相同的故障。

I was going to suggest you try one of the alternative online converters.我打算建议您尝试一种替代的在线转换器。 But I just tried them and neither properly handles your SVG either.但我只是尝试过它们,也没有正确处理您的 SVG。 Perhaps you can try a different icon set, or try to recreate these ones in a vector editor, like Inkscape.也许您可以尝试不同的图标集,或者尝试在矢量编辑器中重新创建这些图标,例如 Inkscape。

It should be a Android Studio bug: Using the Android Studio integrated SVG to XML tool cause this problem.应该是 Android Studio 的错误:使用 Android Studio 集成的 SVG to XML 工具会导致此问题。

You can get the XML file with other SVG to XML conversion tools like this to get the XML, then paste it to XML.您可以使用其他像这样的SVG 到 XML 转换工具获取 XML 文件以获取 XML,然后将其粘贴到 XML。 It should works.它应该有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM