-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathrequirejs.html
More file actions
72 lines (65 loc) · 2.69 KB
/
requirejs.html
File metadata and controls
72 lines (65 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
</head>
<body>
Choose image(s) to decode:
<input id="ipt-file" type="file" multiple accept="image/png,image/jpeg,image/bmp,image/gif">
<br><br>
<button id="btn-show-scanner">show scanner</button>
<script>
// reader for decoding picture
let pReader = null;
// scanner for decoding video
let pScanner = null;
requirejs(['https://cdn.jsdelivr.net/npm/[email protected]/dist/dbr.js'], function({DBR,BarcodeReader,BarcodeScanner}){
// Please visit https://www.dynamsoft.com/customer/license/trialLicense/?product=dbr&utm_source=github&package=js to get a trial license.
DBR.productKeys = "PRODUCT-KEYS";
// DBR._bUseFullFeature = true; // Control of loading min wasm or full wasm.
// decode input picture
document.getElementById('ipt-file').addEventListener('change', async function(){
try{
let reader = await (pReader = pReader || BarcodeReader.createInstance());
let resultsToAlert = [];
for(let i = 0; i < this.files.length; ++i){
let file = this.files[i];
resultsToAlert.push(i + '. ' + file.name + ":");
let results = await reader.decode(file);
console.log(results);
for(let result of results){
resultsToAlert.push(result.barcodeText);
}
}
alert(resultsToAlert.join('\n'));
}catch(ex){
alert(ex.message);
throw ex;
}
this.value = '';
});
// decode video from camera
document.getElementById('btn-show-scanner').addEventListener('click', async () => {
try{
let scanner = await (pScanner = pScanner || BarcodeScanner.createInstance());
scanner.onFrameRead = results => {
if(results.length){
console.log(results);
}
};
scanner.onUnduplicatedRead = (txt, result) => {
alert(result.barcodeFormatString + ': ' + txt);
};
await scanner.show();
}catch(ex){
alert(ex.message);
throw ex;
}
});
});
</script>
</body>
</html>