css - 应用 CSS3 :Zoom on the element? 时关闭 svg 上的抗锯齿

标签 css svg antialiasing

我发现当 CSS3 缩放应用于小 SVG 图标时(9px:9px 缩放:1.5),SVG 图标可能会模糊。在这种情况下,有什么办法可以得到清晰明了的图标吗?提前致谢。

SVG:

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve"
         x="0px" y="0px" width="9px" height="9px" viewBox="0 0 9 9" enable-background="new 0 0 9 9">
    <g>
        <g fill="none" transform="translate(0.5, 0.5)"> 
            <g stroke="#000000" stroke-width="0.5" stroke-linecap="square" >
                <line x1="2" y1="4"  x2="6" y2="4"/>
                <line x1="4"  y1="2" x2="4" y2="6"/>
            </g>
            <g stroke="#909090" stroke-width="1" stroke-linecap="square" >
                <rect x="0" y="0" width="8" height="8"/>
            </g>
        </g>
    </g>
</svg>

最佳答案

我自己找到了解决方案。诀窍是添加:

shape-rendering="crispEdges"

到 SVG 元素。

来自 Mozilla MDN :

crispEdges Indicates that the user agent shall attempt to emphasize the contrast between clean edges of artwork over rendering speed and geometric precision. To achieve crisp edges, the user agent might turn off anti-aliasing for all lines and curves or possibly just for straight lines which are close to vertical or horizontal. Also, the user agent might adjust line positions and line widths to align edges with device pixels.

查看 jsFilddle 上的差异.

关于css - 应用 CSS3 :Zoom on the element? 时关闭 svg 上的抗锯齿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16889078/

相关文章:

html - 如何将相对路径添加到 PIE.htc 文件?

javascript - D3.js 如何获取 x 和 y 轴的位置/偏移量

css - 如何使用 svg 形状来遮盖图像?

c++ - 没有 OpenGL 的 SDL 抗锯齿?

css - PC 上的@font-face 别名问题

html 正文小于其内容

javascript - 如何从 PHP echo sql 语句中删除前导零?

html - CSS 主体和标题问题

javascript - 如何在到达页面中的特定点时为 svg 路径设置动画?

android - OpenGL ES 2.0 通过共享 C++ 代码在 ios 和 android 上进行抗锯齿或平滑处理