图形绘制完毕添加 this.context.fill() 即可填充颜色,可参考如下demo:@Entry @Component struct BezierCurveTo { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Canvas(this.context) .backgroundColor('#ffff00') .width('100%') .height('100%') .onReady(() => { this.context.strokeStyle = "#333" this.context.fillStyle = '#ffe514d0' this.context.lineWidth = 2 this.context.beginPath() this.context.moveTo(30, 30) this.context.lineTo(30, 150) this.context.lineTo(100, 150) this.context.lineTo(100, 80) this.context.bezierCurveTo(75, 20, 75, 20, 30, 30) this.context.stroke() this.context.fill() this.context.beginPath() this.context.moveTo(100, 80) this.context.lineTo(100, 150) this.context.lineTo(150, 150) this.context.lineTo(150, 120) this.context.bezierCurveTo(130, 90, 160, 30, 100, 80) this.context.stroke() this.context.fillStyle = '#ff1f7fe5' this.context.fill() }) } .width('100%') .height('100%') } }
图形绘制完毕添加 this.context.fill() 即可填充颜色,可参考如下demo: