微信小程序API 繪圖beginPath(開始一個(gè)路徑)

2022-05-09 16:44 更新

微信小程序 canvas接口和方法繪圖接口和方法

canvasContext.beginPath


定義

開始創(chuàng)建一個(gè)路徑,需要調(diào)用fill或者stroke才會(huì)使用路徑進(jìn)行填充或描邊。

Tip: 在最開始的時(shí)候相當(dāng)于調(diào)用了一次beginPath()。

Tip: 同一個(gè)路徑內(nèi)的多次setFillStyle()、setStrokeStyle()setLineWidth()等設(shè)置,以最后一次設(shè)置為準(zhǔn)。

例子

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


微信小程序 canvas接口和方法繪圖接口和方法

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)