Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program API drawing closePath (close a path)


May 19, 2021 WeChat Mini Program Development Document


Table of contents


WeChat small program API drawing closePath (close a path) Drawing interfaces and methods

canvasContext.closePath


Defined

Close a path

Tip : Closing the path connects the start and end points.

Tip : If fill() stroke() closed and a new path is opened, the previous path will not be rendered.

Example

const ctx = wx.createCanvasContext('myCanvas')
ctx.moveTo(10, 10)
ctx.lineTo(100, 10)
ctx.lineTo(100, 100)
ctx.closePath()
ctx.stroke()
ctx.draw()

WeChat small program API drawing closePath (close a path)

const ctx = wx.createCanvasContext('myCanvas')
// begin path
ctx.rect(10, 10, 100, 30)
ctx.closePath()

// 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()

WeChat small program API drawing closePath (close a path)

WeChat small program API drawing closePath (close a path) Drawing interfaces and methods