I encapsulate a control with canvas. When it get a coordinate array, it can draw the trajectory the array discribed.But during development process,I met a problem and I will simplify the problem in this question.
First ,let us read the code following.
Canvas {
anchors.centerIn: parent
width: 500
height: 500
Rectangle {
anchors.fill: parent
border.width: 1
color: "transparent"
}
onPaint: {
var ctx = getContext('2d')
ctx.lineWidth = 2
ctx.strokeStyle = "yellow"
ctx.beginPath()
ctx.moveTo(100, 100)
ctx.lineTo(300, 100)
ctx.moveTo(100, 150)
ctx.lineTo(300, 150)
ctx.lineTo(100, 150)
ctx.lineTo(300, 150)
ctx.closePath()
ctx.stroke()
}
}
When I draw along with a line or an arc back and forth, the both ends of the line will automatically draw an extra section.
But the data is large,I can avoid this phenomenon.
So do you konw the solution?Could some one teach me?It is important for me,thanks a lot!
2
Answers
I got an idea,although it is not perfect way but it can meet my needs.Just call the moveTo() the same point after lineTo() .
When called moveTo(),it means the last line has been over.So the rendering problem will not appear.
You can close your path before a call to
moveTo()
. This is somehow just a workaround, I guess:Another workaround is to set the lineWidth below 0.9. This is really strange. Guess, this is a bug.