HarmonyOS 关于canvas中 动态设置lineto?

如题:HarmonyOS 关于canvas中 动态设置lineto?

阅读 557
1 个回答
@Entry
@Component
struct CanvasDemo {
  private settings: RenderingContextSettings = new RenderingContextSettings(true)
  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
  @State @Watch('draw')content: string = ""

  draw() {
    this.context.clearRect(0, 0, 200, 200) // 清理画布内容
    this.context.fillText(this.content, 50, 50) // 重新填充
  }

  build() {
    Column() {
      Canvas(this.context)
        .width('100%')
        .height('25%')
        .backgroundColor('#F5DC62')
        .onReady(() => {
          //可以在这里绘制内容。
          this.context.font = '55px sans-serif'
          this.context.fillText(this.content, 50, 50)
        })
      TextInput({
        text:$$this.content
      })
    }
    .borderColor('#31525B')
    .borderWidth(12)
    .width('100%')
    .height('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进