首页 文章

svg宽度和高度内的图像无法按预期工作

提问于
浏览
2

我尝试在IE 10上使图像灰度工作,经过一些搜索使用svg可以存档它,但现在我遇到另一个问题,这里是IE 10上的代码make image灰度工作

<svg xmlns="http://www.w3.org/2000/svg" id="svgroot" viewBox="0 0 400 377" width="400" height="377">
  <defs>
    <filter id="filtersPicture">
      <feComposite result="inputTo_38" in="SourceGraphic" in2="SourceGraphic" operator="arithmetic" k1="0" k2="1" k3="0" k4="0" />
      <feColorMatrix id="filter_38" type="saturate" values="0" data-filterid="38" />
    </filter>
  </defs>
  <image filter="url(&quot;#filtersPicture&quot;)" x="0" y="0" width="400" height="377" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://thecybershadow.net/misc/stackoverflow.png" />
</svg>

问题是图像不按我给出的尺寸缩放,例如,如果图像的尺寸是200 X 1000并且我给出200 X 500的尺寸,它会将图像缩放到100 X 500

我试过preserveAspectRatio http://www.w3.org/TR/SVG/coords.html#PreserveAspectRatioAttribute似乎不行

所以我的问题是如何使图像调整到我给出的大小?

提前致谢

2 回答

  • 4

    如果希望图像拉伸以精确指定(水平和垂直)指定的宽度和高度,请使用 preserveAspectRatio="none" .

    <image x="0" y="0" width="400" height="377" xlink:href="blah" preserveAspectRatio="none" />
    
  • 1

    没有找到绝对的解决方案,但这项工作符合我们的需求

    使用preserveAspectRatio可以使图像几乎适合我给出的尺寸而且超出部分会被歪曲,所以我可以让图像的比例与我给出的尺寸相似,它会很好

    <image preserveAspectRatio="xMidYMid slice" filter="url(&quot;#filtersPicture&quot;)" x="0" y="0" width="400" height="377" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://192.168.0.10:3000/uploads/photo/609/address/a219c3c5eb8fdce852a61385ae31bc7ee270fc73.jpg" />
    

相关问题