我已经为此挣扎了一段时间,似乎在任何地方都找不到一个(有效的)答案。我有一个SVG文件,看起来像这样:

<svg

   xmlns:dc="http://purl.org/dc/elements/1.1/"
   ...
   width="72.9375"
   height="58.21875"
   ...>
   ...
   <g
     ...
     transform="translate(10.75,-308.96875)"
     style="...">
     <path
       inkscape:connector-curvature="0"
       d="m -10.254587,345.43597 c 0,-1.41732 0.17692,-2.85384 0.5312502,-3.5625 0.70866,-1.41733 2.14518,-2.82259 3.5625,-3.53125 1.41733,-0.70866 2.11392,-0.70867 3.53125,0 1.41732,0.70866 ... z"
       ... />
  </g>
</svg>

我想删除transform="…"行,但仍然有我的图像留在我已经放置它(在InkScape)。如果我手动删除转换,图像将压缩到屏幕的另一部分(正如预期的那样),但我需要完全删除转换,同时让图像保持在我想要的位置。是否有一种方法可以移除/平展转换到路径坐标本身?(我唯一需要处理的变换是平移和缩放,没有矩阵。)


当前回答

虽然我更喜欢Inkscape,但Affinity Designer(约40美元/ Mac)在使用Android Vector Drawables时为我节省了数小时的精力。

打开一个SVG,文件->导出-> SVG ->更多->扁平化转换效果很好。

其他回答

需要提到的是,在首选项中有“优化”模式:

Inkscape首选项>转换>存储转换>优化

这应该尽可能地减少transform属性的出现(但没有)。

这似乎是默认开启的。

根据讨论,这种优化模式缺乏热情的一个实例是页面调整大小时。这将导致翻译转换应用于<g>层元素。目前看来,把孩子们疏散到另一层是最好的解决办法。

在我的例子中,组实际上是由层引起的。删除文档中的所有层删除了组和转换(可能与取消对象分组并重新分组等结合在SVG文件中删除转换(answer-35490189 from @Charlie above))

I tried the solution posted here, namely to remove the group tags in the SVG-file and reopen it in Inkscape (0.48.3.1 in my case). Alas, after I translated the paths again using the select and transform mode (F1) and saved it, the group tags reappeared! Inkscape saves all transformations applied to the path in a surrounding group element. Unless you use the path-node selection tool (F2), hit ctrl+a and move the nodes of the path to their right place. After I had done this instead and saved afterwards Inkscape didn't add the group tags, because this translation applied directly to the path model. Hope this helps.

我已经有这个问题很多年了。解决方案显然是能够在浏览器中动态地发挥转换,如果它不打算“固定”在inkscape。

Inkscape论坛的一位用户Mc给了我这个解决方案。

该解决方案在SVG元素及其SVG根元素之间构建当前转换,然后根据转换的总数返回一组完整的BBox信息。

如果您想在同一SVG文件的两个部分之间进行浏览器工作,还可以轻松地更改计算相对于哪个元素。

最后,我可以实际拥有一个平移SVG视口。

我能够摆脱矩阵(…)变换(由于镜像)通过组合路径与矩形,然后删除矩形的节点。翻译(…)部分留下来了。