Drawing a 1px thick line in canvas creates a 2px thick line

前端 未结 8 1776
抹茶落季
抹茶落季 2020-12-08 04:01

In this jsfiddle there\'s a line with a lineWidth of 1.

http://jsfiddle.net/mailrox/9bMPD/350/

e.g:

ctx.lineWidth = 1;

How

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 04:17

    Canvas calculates from the half of a pixel

    ctx.moveTo(50,150.5);
    ctx.lineTo(150,150.5);
    

    So starting at a half will fix it

    Fixed version: http://jsfiddle.net/9bMPD/357/

    This answer explains why it works that way.

提交回复
热议问题