Skip to content

Instantly share code, notes, and snippets.

@yushulx
Created October 13, 2020 03:23
Show Gist options
  • Save yushulx/cc7d4dd53017230c324ddbc42f9aba79 to your computer and use it in GitHub Desktop.
Save yushulx/cc7d4dd53017230c324ddbc42f9aba79 to your computer and use it in GitHub Desktop.
overlay.addEventListener('mouseup', e => {
if (isDrawing) {
isDrawing = false;
mousePosition.innerHTML = "Cursor: (" + e.offsetX + ", " + e.offsetY + ")";
region.innerHTML = "Decode a region: (" + startX + ", " + startY + ", " + e.offsetX + ", " + e.offsetY + "). ";
overlay.style.cursor = "default";
// Decode a region of the barcode image
(async () => {
let settings = await barcodereader.getRuntimeSettings();
settings.region.regionLeft = startX * 100 / overlay.width;
settings.region.regionTop = startY * 100 / overlay.height;
settings.region.regionRight = e.offsetX * 100 / overlay.width;
settings.region.regionBottom = e.offsetY * 100 / overlay.height;
settings.region.regionMeasuredByPercentage = 1;
barcodereader.updateRuntimeSettings(settings);
try {
let decodingStart = Date.now();
await barcodereader.decode(name.files[0]).then((results) => {
let decodingEnd = Date.now();
let txts = [];
try {
for (let i = 0; i < results.length; ++i) {
txts.push(results[i].BarcodeText);
}
let barcoderesults = txts.join(', ');
catch (e) {
}
});
} catch (error) {
alert(error);
}
})();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment