HarmonyOS/OpenHarmony应用开发-ArkTS画布组件(十二)

鸿蒙时代
发布于 2023-4-13 16:56
浏览
0收藏

beginPath
beginPath(): void
创建一个新的绘制路径。
示例:

.// xxx.ets
.@Entry
.@Component
.struct BeginPath {
.  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('100%')
.        .height('100%')
.        .backgroundColor('#ffff00')
.        .onReady(() =>{
.          this.context.beginPath()
.          this.context.lineWidth = 6
.          this.context.strokeStyle = '#0000ff'
.          this.context.moveTo(15, 80)
.          this.context.lineTo(280, 160)
.          this.context.stroke()
.        })
.    }
.    .width('100%')
.    .height('100%')
.  }
.}

HarmonyOS/OpenHarmony应用开发-ArkTS画布组件(十二)-鸿蒙开发者社区
moveTo
moveTo(x: number, y: number): void
路径从当前点移动到指定点。
参数:
HarmonyOS/OpenHarmony应用开发-ArkTS画布组件(十二)-鸿蒙开发者社区
示例:

.// xxx.ets
.@Entry
.@Component
.struct MoveTo {
.  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('100%')
.        .height('100%')
.        .backgroundColor('#ffff00')
.        .onReady(() =>{
.          this.context.beginPath()
.          this.context.moveTo(10, 10)
.          this.context.lineTo(280, 160)
.          this.context.stroke()
.        })
.    }
.    .width('100%')
.    .height('100%')
.  }
.}

HarmonyOS/OpenHarmony应用开发-ArkTS画布组件(十二)-鸿蒙开发者社区

标签
HarmonyOSOpenHarmony应用开发-ArkTS画布组.docx 30.19K 0次下载
收藏
回复
举报
回复
    相关推荐