When setting the browser zoom to 150% and drawing a line on a canvas, the line is blurry. When I double the width and height of the canvas and downscale it to the original width and height with css, lines are crisp.
The top triangle is blurry while the bottom triangle is crisp: http://jsbin.com/acimiq/1
Is it a browser bug, OS bug or am I missing something?
Related
- Disable Interpolation when Scaling a <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
I've tested on Chrome 27, FF 22 and IE 10 on Windows 7.
<!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>