【问题标题】:SVG Scaling the filling-pattern of an path to the paths sizeSVG 将路径的填充模式缩放到路径大小
【发布时间】:2018-03-28 13:14:28
【问题描述】:

我正在尝试将模式应用于一些路径。 而且我失败的事实是,包含在模式中的图像是 1000px x 500px,而我试图应用这种模式的路径具有不同的、更小的尺寸。 我需要以包含路径的大小应用模式。

如果按比例缩小,比如图案的宽度不够大,我需要重复..

示例代码:

<?xml version="1.0" encoding="UTF-16"?>
  <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" class="svg" viewbox="0 0 463.99999 611.67727">
    <defs>
      <image id="_TEST_{84F53B36-9301-4E21-BE8C-B33492D12FB3}" x="0" y="0" width="1000px" height="500px" transform="rotate(0) translate(0,0) scale(1, 1)" 
       xlink:href="data:image/png;base64, HERE GOES THE BASE64-STRING OF MY IMAGE...."/>
      <pattern id="TESTID" patternUnits="objectBoundingBox" x="0" y="0" width="1" height="1" preserveAspectRatio="xMidYMid slice">
        <use xlink:href="#_TEST_{84F53B36-9301-4E21-BE8C-B33492D12FB3}" x="0" y="0"/>
      </pattern>
      <pattern id="TESTID_90" patternUnits="objectBoundingBox" x="0" y="0" width="1" height="1" preserveAspectRatio="xMidYMid slice" patternTransform="rotate(90)">
        <use xlink:href="#_TEST_{84F53B36-9301-4E21-BE8C-B33492D12FB3}" x="0" y="0"/>
      </pattern>
    </defs>
    <path d="M 379.20854, 526.88581  L 234.64025, 526.88581 L 234.64025, 537.76729 L 390.09002, 537.76729 L 379.20854, 526.88581" style="stroke:rgb(1,0,0);stroke-width:0.1mm" fill="url(#TESTID)"/>
    <path d="M 390.09002, 351.22757  L 390.09002, 1.46559 L 379.20854, 12.34707 L 379.20854, 351.22757 L 390.09002, 351.22757" style="stroke:rgb(4,0,0);stroke-width:0.1mm" fill="url(#TESTID_90)"/>
</svg>

结果:

当我更改图像的宽度和高度或图案的比例时,它在某些路径中不再可见,而在其他路径中它会转换...

有人知道这怎么可能吗?我的问题可以理解吗?

【问题讨论】:

  • 使用 patternContentUnits="objectBoundingBox" 并相应地转换内容。

标签: svg path


【解决方案1】:

使用 patternContentUnits 并没有解决我的问题。 我现在用我的模式中的“viewbox”解决了这个问题。此属性设置为图像的大小。作品:-)

感谢@RobertLongson 的回答 :-)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-08
    • 1970-01-01
    • 1970-01-01
    • 2020-03-14
    • 1970-01-01
    • 2018-07-18
    相关资源
    最近更新 更多