我有一个SVG形状(平行四边形),充满了图像.这个演示可以在这里看到.
SVG对象是:
<svg style="overflow:visible; margin-left:111px; margin-top:22px; " height="86" width="281">
<defs>
<pattern id="blip1" patternUnits="userSpaceOnUse" width="279" height="83">
<image xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://i.imgur.com/uTDpE6J.jpg" width="279" height="83"></image>
</pattern>
</defs>
<polygon points="49,2 280,2 232,84 1,84" x="1" y="1" style="stroke-linejoin:round; fill:url(#blip1); stroke-width:2; stroke:hsl(212,45%,26%); "></polygon>
</svg>Run Code Online (Sandbox Code Playgroud)
但是图像没有被拉伸到形状的边界,而是位于形状的中间.
我想要实现的是:

但我得到的是这样的:

谁能建议我一个适用于所有形状的解决方案(即五边形,六边形,星形等)?顺便说一句,它已经可以用椭圆工作了.
oll*_*_uk 13
添加preserverAspectRatio=none到图像对象并将宽度/高度设置为100%似乎可以满足您的需求.更新了小提琴
<svg style="overflow:visible; margin-left:111px; margin-top:22px; " height="86" width="281">
<defs>
<pattern id="blip1" patternUnits="userSpaceOnUse" width="279" height="83">
<image preserveAspectRatio="none" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://i.imgur.com/uTDpE6J.jpg" width="279" height="83"></image>
</pattern>
</defs>
<polygon points="49,2 280,2 232,84 1,84" x="1" y="1" style="stroke-linejoin:round; fill:url(#blip1); stroke-width:2; stroke:hsl(212,45%,26%); ">
</polygon>
</svg>Run Code Online (Sandbox Code Playgroud)