HarmonyOS ArkTS扫描UI该如何实现

HarmonyOS
2024-12-18 16:46:43
浏览
收藏 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%")
  }
}
分享
微博
QQ
微信
回复
2024-12-18 19:08:26
相关问题
ArkTS中globalThis无法使用如何替换
2723浏览 • 1回复 待解决
如何使用ArkTS编写UI界面?
1053浏览 • 1回复 待解决
HarmonyOS代码规范扫描的方案及实现
349浏览 • 1回复 待解决
ArkTS语法校验报错,如何处理啊?
1310浏览 • 1回复 待解决
HarmonyOS customScan 如何扫描本地图片
357浏览 • 1回复 待解决
HarmonyOS ArkTS如何实现反射
261浏览 • 1回复 待解决
HarmonyOS UI实现咨询
266浏览 • 1回复 待解决
鸿蒙平台 UI审核如何实现
5553浏览 • 1回复 待解决
HarmonyOS 关于ArkTS UI样式文件的疑问
839浏览 • 1回复 待解决
HarmonyOS GridView实现键盘UI
362浏览 • 1回复 待解决
HarmonyOS ArkTS 如何实现浅拷贝?
529浏览 • 1回复 待解决
HarmonyOS ArkTS bigint 除法如何实现
263浏览 • 1回复 待解决
HarmonyOS wifi 扫描问题
908浏览 • 1回复 待解决
ArkTS如何实现反射?
1116浏览 • 1回复 待解决