使用Canvas绘制图形请参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-drawing-customization-on-canvas-V5示例代码:@Entry @Component struct test { 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) .width('90%') .height(300) .backgroundColor('#ffff00') .onReady(() => { let radius = 10; //圆角弧度 let x = 40; //左上角坐标x let y = 40; //左上角坐标y let width = 100; //矩形宽 let height = 40; //矩形高 this.context.beginPath(); this.context.moveTo(x + radius, y); this.context.lineTo(x + width - radius, y); this.context.arcTo(x + width, y, x + width, y + radius, radius); this.context.lineTo(x + width, y + height - radius); this.context.arcTo(x + width, y + height, x + width - radius, y + height, radius); this.context.lineTo(x + radius, y + height); this.context.arcTo(x, y + height, x, y + height - radius, radius); this.context.lineTo(x, y + radius); this.context.arcTo(x, y, x + radius, y, radius); this.context.closePath(); this.context.fill(); }) } .width('100%') .height('100%') } }或者可以尝试下ArkTS的绘制组件:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-drawing-components-rect-V5
使用Canvas绘制图形请参考:
https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-drawing-customization-on-canvas-V5
示例代码:
或者可以尝试下ArkTS的绘制组件:
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-drawing-components-rect-V5