开始创建一个路径,需要调用fill或者stroke才会使用路径进行填充或描边。
tip: 在最开始的时候相当于调用了一次beginpath()
。
tip: 同一个路径内的多次setfillstyle()
、setstrokestyle()
、setlinewidth()
等设置,以最后一次设置为准。
const ctx = wx.createcanvascontext('mycanvas')
// begin path
ctx.rect(10, 10, 100, 30)
ctx.setfillstyle('yellow')
ctx.fill()
// begin another path
ctx.beginpath()
ctx.rect(10, 40, 100, 30)
// only fill this rect, not in current path
ctx.setfillstyle('blue')
ctx.fillrect(10, 70, 100, 30)
ctx.rect(10, 100, 100, 30)
// it will fill current path
ctx.setfillstyle('red')
ctx.fill()
ctx.draw()