我正在尝试想出一种最佳的方法,在SVG多边形元素中包含一张图片,如下所示:
<svg id="graph" width="100%" height="400px">
<!-- pattern -->
<defs>
<pattern id="image" x="0%" y="0%" height="100%" width="100%"
viewBox="0 0 64 64">
<image x="0%" y="0%" width="64" height="64" xlink:href="https://cdn4.iconfinder.com/data/icons/imod/512/Software/labo.png"></image>
</pattern>
</defs>
<polygon stroke="red" stroke-width="2px" fill="url(#image)" points="300,150 225,280 75,280 0,150 75,20 225,20"></polygon>
</svg>
然而,我还想用背景颜色fill
填充这个, 但是由于它使用了上述的图案,所以我不确定正确的方法是什么。
defs
中使用相同的原始多边形。 - Andrew Willemspattern
元素中的原始示例中,例如将viewBox
值从0 0 64 64
更改为0 0 128 128
,然后再更改为-32 -32 128 128
,以查看一些方法来实现此目的。但是,我认为您不能在不同的use
元素中使用基于相同图像的相同图案,并具有不同的大小/位置。您需要复制pattern
元素本身并更改其表示属性。 - Andrew Willems