Dokumentasi pembangunan applet WeChat
/ 微信小程序API 繪圖fill(對當前路徑進行填充)
微信小程序API 繪圖fill(對當前路徑進行填充)
fill
定義
對當前路徑中的內(nèi)容進行填充。默認的填充色為黑色。
Tip: 如果當前路徑?jīng)]有閉合,fill()
方法會將起點和終點進行連接,然后填充,詳情見例一。
Tip: fill()
填充的的路徑是從 beginPath()
開始計算,但是不會將 fillRect()
包含進去,詳情見例二。
例子
const ctx = wx.createCanvasContext('myCanvas') ctx.moveTo(10, 10) ctx.lineTo(100, 10) ctx.lineTo(100, 100) ctx.fill() ctx.draw()
const ctx = wx.createCanvasContext('myCanvas')// begin pathctx.rect(10, 10, 100, 30) ctx.setFillStyle('yellow') ctx.fill()// begin another pathctx.beginPath() ctx.rect(10, 40, 100, 30)// only fill this rect, not in current pathctx.setFillStyle('blue') ctx.fillRect(10, 70, 100, 30) ctx.rect(10, 100, 100, 30)// it will fill current pathctx.setFillStyle('red') ctx.fill() ctx.draw()