要实现一个黑色半透明的遮罩,然后挖空一个圆角矩形,这部分是全透明的,可以看到原来的圆角矩形的内容。
我能通过CanvasRenderingContext2D的clearRect来挖空一个矩形,但是没看到有自定义形状的API。
Canvas(this.context)
.width('100%')
.height('100%')
.backgroundColor(Color.Transparent)
.onReady(() =>{
this.context.fillStyle = '#99000000'
if (this.isLandscape) {
this.context.fillRect(0, 0, this.deviceHeight, this.deviceWidth)
} else {
this.context.fillRect(0, 0, this.deviceWidth, this.deviceHeight)
}
// TODO: 这里是要挖空圆角矩形。但是HarmonyOS没有这个API
this.context.clearRect(this.area?.globalPosition.x as number, this.area?.globalPosition.y as number, 75, 30);
})
您参考一下这个demo: