HarmonyOS ArkTS扫描UI该如何实现

HarmonyOS
2024-12-18 16:46:43
1147浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Excelsior_abit
@Entry
@Component
struct Page240419172038091_bak {
  private settings: RenderingContextSettings = new RenderingContextSettings(true)
  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
  private screenCenterX: number = 0
  private screenCenterY: number = 0
  @State sCanLineY: number = 0

  build() {
    Stack({ alignContent: Alignment.Center }) {
      Image($r("app.media.bg")).width(200)
      Canvas(this.context).width("100%").height("100%").backgroundColor(Color.Transparent).onReady(() => {
        let canvasWidth = this.context.width
        let canvasHeight = this.context.height
        this.screenCenterX = canvasWidth / 2
        this.screenCenterY = canvasHeight / 2
        this.context.fillStyle = "#80000000"
        this.context.beginPath()
        this.context.moveTo(0, 0)
        this.context.lineTo(0, this.context.height)
        this.context.lineTo(this.context.width, this.context.height)
        this.context.lineTo(this.context.width, 0)
        this.context.lineTo(0, 0)
        this.context.fill()
        this.context.clearRect(this.screenCenterX - 100, this.screenCenterY - 100, 200, 200)
        this.context.beginPath();
        this.context.moveTo(this.screenCenterX, this.screenCenterY)
        this.context.fillStyle = "#802ac327";
        this.context.fillRect(this.screenCenterX - 100, this.screenCenterY - 100, 200, 2)
        setInterval(() => {
          this.context.clearRect(this.screenCenterX - 100, this.screenCenterY - 100, 200, 200)
          if (this.sCanLineY > 197) {
            this.sCanLineY = 0
          } else {
            this.sCanLineY++
          }
          this.context.fillRect(this.screenCenterX - 100, this.screenCenterY - 100 + this.sCanLineY, 200, 2)
        }, 8)
      })
    }.width("100%").height("100%")
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
分享
微博
QQ
微信
回复
2024-12-18 19:08:26
相关问题
HarmonyOS代码规范扫描的方案及实现
753浏览 • 1回复 待解决
arkts中的this如何使用呢
274浏览 • 0回复 待解决
ArkTS中globalThis无法使用如何替换
3281浏览 • 1回复 待解决
如何使用ArkTS编写UI界面?
1587浏览 • 1回复 待解决
ArkTS语法校验报错,如何处理啊?
1770浏览 • 1回复 待解决
HarmonyOS customScan 如何扫描本地图片
690浏览 • 1回复 待解决
HarmonyOS UI实现咨询
531浏览 • 1回复 待解决
HarmonyOS wifi 扫描问题
1303浏览 • 1回复 待解决
HarmonyOS ArkTS如何实现反射
593浏览 • 1回复 待解决
鸿蒙平台 UI审核如何实现
6067浏览 • 1回复 待解决
HarmonyOS 关于ArkTS UI样式文件的疑问
1243浏览 • 1回复 待解决
HarmonyOS GridView实现键盘UI
706浏览 • 1回复 待解决