Skip to content

Instantly share code, notes, and snippets.

@jackyef
Created July 16, 2019 05:42
Show Gist options
  • Select an option

  • Save jackyef/ff6b15520867fca25c3cf7345d30ae26 to your computer and use it in GitHub Desktop.

Select an option

Save jackyef/ff6b15520867fca25c3cf7345d30ae26 to your computer and use it in GitHub Desktop.
function captureImage() {
const { decode_qr } = wasm_bindgen;
const video = document.getElementById('video');
const canvas = document.createElement('canvas');
const scale = 0.25; // we scale the image down to improve performance
canvas.width = video.videoWidth * scale;
canvas.height = video.videoHeight * scale;
canvas
.getContext("2d")
.drawImage(video, 0, 0, canvas.width, canvas.height);
canvas.toBlob(blob => {
const reader = new FileReader();
reader.addEventListener("loadend", () => {
const arrayBuffer = reader.result;
const output = decode_qr(new Uint8Array(arrayBuffer));
console.log("output of decode_qr:", output);
});
reader.readAsArrayBuffer(blob);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment