HarmonyOS 扫码页面的扫描线实现方式吗 ?

默认扫码页面,上下扫描效果的示例代码供参考 ,或者使用到的技术,使用canvas绘制?

HarmonyOS
2024-10-29 12:01:15
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
FengTianYa

看下以下 demo:

@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-10-29 16:37:50
相关问题
HarmonyOS h5拉起系统页面的demo
1316浏览 • 1回复 待解决
HarmonyOS 支持扫描二维
1370浏览 • 1回复 待解决
HarmonyOS 如何自定义页面
872浏览 • 1回复 待解决
实现的库有哪些 ,有人知道
2084浏览 • 1回复 待解决
HarmonyOS 需要实现音效播放问题
1152浏览 • 1回复 待解决
JS如何实现手机功能?
3983浏览 • 1回复 待解决
HarmonyOS 直达问题
1018浏览 • 1回复 待解决
HarmonyOS 需要demo
1084浏览 • 1回复 待解决
HarmonyOS模块”通用能力
1073浏览 • 1回复 待解决
HarmonyOS 服务权限问题
1147浏览 • 1回复 待解决
相册识别多失败
2926浏览 • 1回复 待解决
HarmonyOS 是否有功能
971浏览 • 1回复 待解决
HarmonyOS 自定义咨询
802浏览 • 1回复 待解决