我使用这个二维码扫描仪: https://github.com/mebjas/html5-qrcode
我用这段代码扫描二维码:
function onScanSuccess(decodedText, decodedResult) {
// handle the scanned code as you like, for example:
document.getElementById('text').value = decodedText;
console.log(`Code matched = ${decodedText}`, decodedResult);
}
function onScanFailure(error) {
// handle scan failure, usually better to ignore and keep scanning.
// for example:
console.warn(`Code scan error = ${error}`);
}
let html5QrcodeScanner = new Html5QrcodeScanner(
"reader", { fps: 10, qrbox: 250 }, /* verbose= */ false);
html5QrcodeScanner.render(onScanSuccess, onScanFailure);
可以将默认相机设置为后置 smartfone 相机。我想在启动时使用后置摄像头运行扫描仪。 谢谢,一些帮助。
最佳答案
我在启动扫描器时使用这段代码完成了它:
facingMode: { exact: "environment"}
也许这会帮助您指明正确的方向。以下是我启动扫描仪时使用设置的方式:
/** load scanner using back camera **/
html5QrCode.start({ facingMode: { exact: "environment"} }, config, qrCodeSuccessCallback);
关于javascript - 在 html5-qrcode.min.js 上选择后置摄像头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68812749/