清除画布上在该矩形区域内的内容。
tip: clearrect 并非画一个白色的矩形在地址区域,而是清空,为了有直观感受,对 canvas 加了一层背景色。
<canvas canvas-id="mycanvas" style="border: 1px solid; background: #123456;"/>
参数 | 类型 | 说明 |
---|---|---|
x | number | 矩形区域左上角的x坐标 |
y | number | 矩形区域左上角的y坐标 |
width | number | 矩形区域的宽度 |
height | number | 矩形区域的高度 |
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()