【问题标题】:Disable antialising when scaling images [duplicate]缩放图像时禁用抗锯齿[重复]
【发布时间】:2012-12-13 15:15:33
【问题描述】:

可能重复:
How to stretch images with no antialiasing

是否可以在放大图像时以任何方式禁用抗锯齿?

现在,我得到的东西看起来像这样:

使用以下 css 代码:

#bib {
    width: 104px;
    height: 104px;
    background-image: url(/media/buttonart_back.png);
    background-size: 1132px 1360px;
    background-repeat: no-repeat;
}

我想要的是这样的:

简而言之,任何 CSS 标志都可以在放大图像时禁用抗锯齿,保留硬边。

也欢迎任何 javascript hack 或类似内容。

(是的,我知道 php 和 imagemagick 也可以做到这一点,但更喜欢基于 css 的解决方案。)

更新 建议如下:

image-rendering: -moz-crisp-edges;
image-rendering: -moz-crisp-edges;
image-rendering: -o-crisp-edges;
image-rendering: -webkit-optimize-contrast;
-ms-interpolation-mode: nearest-neighbor;

但这似乎不适用于背景图像。

【问题讨论】:

    标签: css background-image antialiasing


    【解决方案1】:

    试试这个, 这是在所有浏览器中删除它的修复程序。

    img { 
        image-rendering: optimizeSpeed;             /* STOP SMOOTHING, GIVE ME SPEED  */
        image-rendering: -moz-crisp-edges;          /* Firefox                        */
        image-rendering: -o-crisp-edges;            /* Opera                          */
        image-rendering: -webkit-optimize-contrast; /* Chrome (and eventually Safari) */
        image-rendering: pixelated; /* Chrome */
        image-rendering: optimize-contrast;         /* CSS3 Proposed                  */
        -ms-interpolation-mode: nearest-neighbor;   /* IE8+                           */
    
    }
    

    来源:

    http://nullsleep.tumblr.com/post/16417178705/how-to-disable-image-smoothing-in-modern-web-browsers

    http://updates.html5rocks.com/2015/01/pixelated

    GitaarLAB

    【讨论】:

    • 很遗憾,这在 Chrome 中不起作用。
    • 我看到这在我的 iMac 上的 Chrome 版本 40.0.2214.115(64 位)中工作
    • 从 passsss 中爆炸......呃未来:):您可能希望将当前的 CSS3 标准添加到列表中:image-rendering: pixelated,请参阅:updates.html5rocks.com/2015/01/pixelated
    • 这不适用于 WebKit 上的背景图像。不知道是不是bug。
    • @Kasper Sebastian Brandt Jensen,当使用 css 属性 transform: scale(2)...
    【解决方案2】:

    适用于 Firefox Only 的 CSS:

    img { image-rendering: -moz-crisp-edges; } 
    

    它对我有用(firefox 16.0)

    【讨论】:

    • 不错。但我猜其他浏览器没有类似的键?
    • 没有。至少我不知道...:)
    猜你喜欢
    • 2021-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 2010-12-16
    • 1970-01-01
    • 1970-01-01
    • 2011-08-30
    相关资源
    最近更新 更多