小程序畫布清除畫布上矩形區域內的內容CanvasContext.clearRect
CanvasContext.clearRect(number x, number y, number width, number height)
清除畫布上在該矩形區域內的內容
小程序插件:支持
參數
number x
矩形路徑左上角的橫坐標
number y
矩形路徑左上角的縱坐標
number width
矩形路徑的寬度
number height
矩形路徑的高度
示例代碼
clearRect 并非畫一個白色的矩形在地址區域,而是清空,為了有直觀感受,對 canvas 加了一層背景色。
<canvas canvas-id="myCanvas" style="border: 1px solid; background: #123456;"/>
const ctx = wx.createCanvasContext('myCanvas')
ctx.setFillStyle('red')
ctx.fillRect(0, 0, 150, 200)
ctx.setFillStyle('blue')
ctx.fillRect(150, 0, 150, 200)
ctx.clearRect(10, 10, 150, 75)
ctx.draw()
計算機學習推薦