最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - QR scanner on angular project not choosing the right camera - Stack Overflow

programmeradmin1浏览0评论

I've got this QR scanner on my component and it works, but has a problem: in some devices (mostly devices with 3 or more cameras like iPhone Pro) it doesn't get the camera for short distances (the one used by the default camera to scan QR codes) and it takes a lot to scan them. You can't be too close or it'll be blurry, and when on focus you need to angle it perfectly or else it doesn't get scanned. I've tried to make it take the right camera with onCamerasFound, but it doesn't seem to work. What am I doing wrong? If you need more info on the code or in general feel free to ask.

HTML:

<zxing-scanner 
  [device]="selectedDevice" 
  (camerasFound)="onCamerasFound($event)"
  (scanSuccess)="onQrCodeScanComplete($event)"
  style="width: 100%; max-height: 50vh;">
</zxing-scanner>

TS:

 onCamerasFound(devices: MediaDeviceInfo[]) {
    if (devices.length > 0) {
      const backCameras = devices.filter(device => 
        device.label.toLowerCase().includes('back') || 
        device.label.toLowerCase().includes('rear')
      );
      this.selectedDevice = backCameras.length > 0 ? backCameras[0] : devices[0];
    }
  }
发布评论

评论列表(0)

  1. 暂无评论