Closed randomprogramming closed 2 years ago
Stupid mistake, adding:
canvas.height = img.naturalHeight;
canvas.width = img.naturalWidth;
Fixed the problem...
Thank you so much, You've been very helpful..
https://codepen.io/04/pen/xxmwXNe?editors=1010
async function scanQRFromFile(file) {
const img = new Image();
img.src = URL.createObjectURL(file);
await new Promise((resolve) => img.addEventListener("load", resolve));
const canvas = new OffscreenCanvas(img.naturalWidth, img.naturalHeight);
const ctx = canvas.getContext("2d");
ctx.imageSmoothingEnabled = false;
ctx.drawImage(img, 0, 0);
const imageData = ctx.getImageData(0, 0, img.naturalWidth, img.naturalHeight);
return jsQR(imageData.data, img.naturalWidth, img.naturalHeight)?.data;
}
imageData.data is defined when logging
code is logged as null
Sample QR that doesn't work with this approach: