cozmo / jsQR

A pure javascript QR code reading library. This library takes in raw images and will locate, extract and parse any QR code found within.
https://cozmo.github.io/jsQR/
Apache License 2.0
3.73k stars 607 forks source link

Code with Chinese can't be parsed #214

Open VincentTV opened 3 years ago

VincentTV commented 3 years ago

These two QR codes are generated using the same way, and the one on the left that contains Chinese cannot be parsed.

qrcode

Return Data: Res

dlwe commented 2 years ago

Another example. https://upload.wikimedia.org/wikipedia/commons/3/32/Japan-qr-code-billboard.jpg in https://en.wikipedia.org/wiki/QR_code Japan-qr-code-billboard

The content of this QR code is "http://sagasou.mobi

MEBKM:TITLE:探そうモビで専門学校探し!;URL:http\://sagasou.mobi;;". jsQR returns code, but code.data is an empty string.

Arno500 commented 2 years ago

Due to how "data" is handled in this lib, you may not use it if the code doesn't contain ASCII data (which it does not, here). You also happen to use an old text encoding (notably GBK) and in JS this is not exactly trivial to handle traditionally. You may instead use "binaryData" and a TextDecoder in this way:

new TextDecoder("gbk").decode(Uint8Array.from(result.binaryData))

And that'll give you the string you were trying to get.

fengdh commented 2 years ago

You must use correct encoding to parse raw result.