将浏览器缩放设置为 150% 并在画布上绘制线条时,线条模糊。当我将画布的宽度和高度加倍并使用 css 将其缩小到原始宽度和高度时,线条清晰。
顶部三角形模糊,底部三角形清晰:http: //jsbin.com/acimiq/1
是浏览器错误、操作系统错误还是我遗漏了什么?
有关的
- 缩放 <canvas> 时禁用插值
- http://www.html5rocks.com/en/tutorials/canvas/hidpi/
- http://phoboslab.org/log/2012/09/drawing-pixels-is-hard
- http://elev.at/predawnblog/posts/2011/03/crisp-html-5-canvas-text-on-mobile-phones-and.html
我已经在 Windows 7 上的 Chrome 27、FF 22 和 IE 10 上进行了测试。
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>canvas test</title>
<style id="jsbin-css">
#canvas1 {
image-rendering: optimizeSpeed; // Older versions of FF
image-rendering: -moz-crisp-edges; // FF 6.0+
image-rendering: -webkit-optimize-contrast; // Webkit
// (Safari now, Chrome soon)
image-rendering: -o-crisp-edges; // OS X & Windows Opera (12.02+)
image-rendering: optimize-contrast; // Possible future browsers.
-ms-interpolation-mode: nearest-neighbor; // IE
}
#canvas2 {
width: 300px;
height: 150px;
}
</style>
</head>
<body>
<canvas id="canvas1" width="300" height="150"></canvas>
<br/>
<canvas id="canvas2" width="600" height="300"></canvas>
<script>
var canvas1 = document.getElementById('canvas1');
var ctx1 = canvas1.getContext('2d');
ctx1.imageSmoothingEnabled = false;
ctx1.webkitImageSmoothingEnabled = false;
ctx1.mozImageSmoothingEnabled = false;
ctx1.beginPath();
ctx1.moveTo(125,125);
ctx1.lineTo(125,45);
ctx1.lineTo(45,125);
ctx1.closePath();
ctx1.stroke();
var canvas2 = document.getElementById('canvas2');
var ctx2 = canvas2.getContext('2d');
ctx2.scale(2, 2);
ctx2.beginPath();
ctx2.moveTo(125,125);
ctx2.lineTo(125,45);
ctx2.lineTo(45,125);
ctx2.closePath();
ctx2.stroke();
</script>
</body>
</html>