HarmonyOS/OpenHarmony アプリケーション開発 - ArkTS キャンバス コンポーネント CanvasRenderingContext2D オブジェクト (12)

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%')
.  }
.}


moveTo
moveTo(x: number, y: number): void
パスは、現在のポイントから指定されたポイントに移動します。
パラメータ:

例:

.// 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%')
.  }
.}

おすすめ

転載: blog.csdn.net/weixin_69135651/article/details/130134917
おすすめ