在 Android 浏览器上使用 Ionic QRScanner 时出现问题:放大太多
issue using Ionic QRScanner on Android browser: zoom in too much
我在 Ionic 4/Angular 浏览器应用程序中使用 https://ionicframework.com/docs/native/qr-scanner。
该应用程序在笔记本电脑浏览器上运行良好,可以使用相机预览和读取二维码。
但是,在 Android 浏览器上尝试时,相机放大太多,无法扫描代码。
网上没有太多内容(只是有人要求在插件中添加缩放 in/out 功能),我试图通过另一个插件 (https://ionicframework.com/docs/native/camera-preview) 来控制相机缩放,但没有成功没用。
有人知道如何解决这个问题吗?
作为参考,我将我的代码附加在本邮件的末尾。
谢谢,
scanCode() {
console.log('entering scan function');
this.qrScanner.prepare()
.then((status: QRScannerStatus) => {
console.log('checking status');
if (status.authorized) {
this.statusScanning=true;
// camera permission was granted
console.log('camera permission granted');
// start scanning
this.scanSub = this.qrScanner.scan().subscribe( (scanRes: string) => {
let object:any=scanRes;
if(isDefined(object.result))
{
let text: string=""+object.result;
this.myfunction(text);
this.qrScanner.hide(); // hide camera preview
this.scanSub.unsubscribe(); // stop scanning
}
});
} else if (status.denied) {
// camera permission was permanently denied
// you must use QRScanner.openSettings() method to guide the user to the settings page
// then they can grant the permission from there
console.log('status denied');
} else {
console.log('permissions denied for now');
// permission was denied, but not permanently. You can ask for permission again at a later time.
}
})
.catch((e: any) => console.log('Error:', e));
}
万一有人遇到我遇到的同样问题,我发现最好的选择是放弃 QRScanner 组件并使用 jsQR。
我遵循了本页 (https://devdactic.com/pwa-qr-scanner-ionic/) 教程中的原则,最终一切正常。
干杯,
我在 Ionic 4/Angular 浏览器应用程序中使用 https://ionicframework.com/docs/native/qr-scanner。
该应用程序在笔记本电脑浏览器上运行良好,可以使用相机预览和读取二维码。
但是,在 Android 浏览器上尝试时,相机放大太多,无法扫描代码。
网上没有太多内容(只是有人要求在插件中添加缩放 in/out 功能),我试图通过另一个插件 (https://ionicframework.com/docs/native/camera-preview) 来控制相机缩放,但没有成功没用。
有人知道如何解决这个问题吗?
作为参考,我将我的代码附加在本邮件的末尾。
谢谢,
scanCode() {
console.log('entering scan function');
this.qrScanner.prepare()
.then((status: QRScannerStatus) => {
console.log('checking status');
if (status.authorized) {
this.statusScanning=true;
// camera permission was granted
console.log('camera permission granted');
// start scanning
this.scanSub = this.qrScanner.scan().subscribe( (scanRes: string) => {
let object:any=scanRes;
if(isDefined(object.result))
{
let text: string=""+object.result;
this.myfunction(text);
this.qrScanner.hide(); // hide camera preview
this.scanSub.unsubscribe(); // stop scanning
}
});
} else if (status.denied) {
// camera permission was permanently denied
// you must use QRScanner.openSettings() method to guide the user to the settings page
// then they can grant the permission from there
console.log('status denied');
} else {
console.log('permissions denied for now');
// permission was denied, but not permanently. You can ask for permission again at a later time.
}
})
.catch((e: any) => console.log('Error:', e));
}
万一有人遇到我遇到的同样问题,我发现最好的选择是放弃 QRScanner 组件并使用 jsQR。 我遵循了本页 (https://devdactic.com/pwa-qr-scanner-ionic/) 教程中的原则,最终一切正常。 干杯,