Home  >  Article  >  Web Front-end  >  html5 canvas的lineWidth属性为何设置1px间隔时看不到间隙?

html5 canvas的lineWidth属性为何设置1px间隔时看不到间隙?

WBOY
WBOYOriginal
2016-06-07 08:43:031623browse

回复内容:

moveTo(5,0); lineTo(5,300) 产生的path上进行stroke实际上是绘制了坐标为4.5到5.5的1像素宽的线。因为canvas是bitmap,所以会虚化为坐标4到6的两个像素宽。

你要画正好一像素得用 moveTo(5.5, 0); lineTo(5.5, 300) 一般画奇数线宽比如1px 要把绘制点设置在一个像素的中间,这样两边各平分.5个像素刚好1px 绘制偶数的,绘制点取整数
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn