[使用quaggajs的功能掃描barcode.在安卓系統上是正常。IOS也可以運行。]
[不過在縮放(zoom)與閃光燈功能(torch)方面,IOS系統卻無效果,請求各位幫忙。]
// 啟動掃描
Quagga.init({
inputStream : {
name : "Live",
type : "LiveStream",
target: document.querySelector('#canvanCode'),
constraints: {
width: p_width,
height: p_height,
facingMode:"environment"
}
},
frequency:20,
decoder : {
readers : ["ean_reader"],
halfSample :true,
patchSize:"x-large",
// patchSize:"medium",
// patchSize:"x-small",
debug: {
drawBoundingBox: false,
showFrequency: false,
drawScanline: false,
showPattern: false
},
multiple: false
}
}, function(err) {
if (err) {
console.log(err);
return
}
var track = Quagga.CameraAccess.getActiveTrack();
track.applyConstraints({advanced: [{zoom: 4}]});
console.log("Initialization finished. Ready to start");
Quagga.start();
Quagga.onDetected(function(data){
console.log(data);
//計次(相同累積次數)
if(code_old_name==data.codeResult.code){
code_old_number=code_old_number+1;
}
else{
code_old_number=0;
code_old_name=data.codeResult.code;
}
//重複3次相同
if(code_old_number>=1){
code_old_number=0;
val=data.codeResult.code;
Quagga.stop();
document.getElementById('key_isbn_number').value=val;
code_old_name=Math.floor(Math.random()*50);
// 傳值
window.opener.document.getElementById('key_isbn_number').value=val;
window.opener.show_call();
window.close();
}
})
});