zxing-js / library

Multi-format 1D/2D barcode image processing library, usable in JavaScript ecosystem.

Home Page:https://zxing-js.github.io/library/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not sure how to scan a code 128 barcode

1PV1 opened this issue · comments

commented

I'm using canvas to crop the image so it has only the barcode, I tryed with the code from https://github.com/zxing-js/library#readme but I'm getting NotFoundException: No MultiFormat Readers were able to detect the code.

Code:

const cropedcanvas = createCanvas(384, 99);
const cropedctx = cropedcanvas.getContext('2d');
cropedctx.drawImage(canvas, 0, 312, 384, 99, 0, 0, 384, 99);
const hints = new Map();
hints.set(DecodeHintType.POSSIBLE_FORMATS, [BarcodeFormat.CODE_128]);
const reader = new MultiFormatReader();
const luminanceSource = new RGBLuminanceSource(new Uint8ClampedArray(cropedcanvas.toBuffer()), cropedcanvas.width, cropedcanvas.height);
const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
const code = reader.decode(binaryBitmap, hints);
console.log(code)

Image:
image