HTML5 Canvas translate(0.5,0.5) not fixing line blurryness

前端 未结 1 1288
误落风尘
误落风尘 2020-12-02 01:21

Reading related articles, I\'ve tried forcing the canvas size in pixels, specifying half pixels for the paths and also context.translate(0.5) but my canvas lines are still b

相关标签:
1条回答
  • 2020-12-02 01:37

    Retina & HiDPI devices

    Looking at the image you supplied. The canvas is half the resolution of the display. Zoom in and look at the pixels on the "X", The DOM line is 1px yet still twice a wide as the pixels on that letter. That means the canvas is being stretched and the blur is due to the bilinear filtering. Either you are zoomed out on the tab or you have a retina or HiDPI display. Set the canvas.width & canvas.height to twice what it is, set the canvas.style.width & canvas.style.height to DOM pixels. Remove the ctx.translate and add ctx.scale(2,2) and all things will be clear.

    A zoom in on the image

    0 讨论(0)
提交回复
热议问题