Created
July 16, 2019 05:42
-
-
Save jackyef/ff6b15520867fca25c3cf7345d30ae26 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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