网络浏览器中的图像稍微模糊。如何禁用它? [英] Images in web browser are slightly blurred. How to disable it?

查看:160
本文介绍了网络浏览器中的图像稍微模糊。如何禁用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个游戏。这个游戏中的碰撞是基于画布上像素的颜色。我得到彩色像素,如果它是红色,玩家不能移动。
不幸的是在Firefox的图像是远程模糊。像素流畅地从白色变为红色。但我不想那样

任何想法如何回答这个问题?

解决方案

这被称为抗锯齿,是重新调整大小后的图像插值结果(或子像素形状,文本等等向前)。这是浏览器在内部执行的操作。



然而,您可以在更新版本的浏览器中关闭此功能。

这是我做了一个测试,看看它是否在浏览器中工作,以及模式之间的差异(如下图) - 底部版本不应平滑:

(与状态尚未准备就绪)指定 crisp-edges 而不是 optimize-contrast 作为未来可能的标准。上面的CSS类更新了这个以反映这个非前缀值。

- 结束更新 -



对于webkit浏览器,你可以像这样禁用canvas元素的图像平滑:

和Mozilla:

  context.mozImageSmoothingEnabled = false; 

(当后者可用时,CSS类不是必须的,除非您缩放任何元素应该避免的情况下)。


I'm making a game. Collisions in this game are based on color of pixel on canvas. I get color pixel and if it is for example red, player can't move. Unfortunately in firefox images are remotely blurred. Pixels are fluently changed from white color to red. But I don't want that. Any ideas how to answer to this problem?

解决方案

This is called anti-aliasing and is a result of interpolating the image when re-sized (or sub-pixeling shapes, text and so forth). It's something the browser do internally.

You can however turn off this in more recent version of the browser.

Here is a test I made to see if this works in your browser and the difference between the modes (as in the picture below) - the bottom version should not be smoothed:

ONLINE TEST

Add this snippet to your CSS style sheet (may or may not work depending on browser):

canvas {
    image-rendering: optimizeSpeed;             // Older versions of FF
    image-rendering: -moz-crisp-edges;          // FF 6.0+
    image-rendering: -webkit-optimize-contrast; // Webkit (non standard naming)
    image-rendering: -o-crisp-edges;            // OS X & Windows Opera (12.02+)
    image-rendering: crisp-edges;               // Possible future browsers.
    -ms-interpolation-mode: nearest-neighbor;   // IE (non standard naming)
}

Update: The current form of the standard (with status "not ready for implementation") specify crisp-edges and not optimize-contrast as possible future standard. CSS class above is updated with this to reflect this for the non-prefixed value.
- end update -

For webkit browsers you can disable image smoothing for the canvas element like this:

context.webkitImageSmoothingEnabled = false;

and for Mozilla:

context.mozImageSmoothingEnabled = false;

(when this latter is available the CSS class is not necessary unless you scale the element itself which in any case should be avoided).

这篇关于网络浏览器中的图像稍微模糊。如何禁用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆