Documentation de développement de l'applet WeChat
/ 微信小程序API 繪圖fill(對(duì)當(dāng)前路徑進(jìn)行填充)
微信小程序API 繪圖fill(對(duì)當(dāng)前路徑進(jìn)行填充)
fill
定義
對(duì)當(dāng)前路徑中的內(nèi)容進(jìn)行填充。默認(rèn)的填充色為黑色。
Tip: 如果當(dāng)前路徑?jīng)]有閉合,fill()
方法會(huì)將起點(diǎn)和終點(diǎn)進(jìn)行連接,然后填充,詳情見例一。
Tip: fill()
填充的的路徑是從 beginPath()
開始計(jì)算,但是不會(huì)將 fillRect()
包含進(jìn)去,詳情見例二。
例子
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()