How to encode characters using UTF-8 in a QR code using the Zxing project?

Zxing Project is a well-known, multi-format 1D / 2D barcode image processing library implemented in Java, with ports in other languages. But I believe that someone has the same problem as me: I cannot encode UTF-8 characters in Qrcode.

How to encode characters using UTF-8 in a QR code using the Zxing project?

+4
source share
2 answers

The right way to do this is to use the hints:

Hashtable hints = new Hashtable(); hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); 

Then call this version of encode in the QRCodeWriter class:

  encode(String contents, BarcodeFormat format, int width, int height,Hashtable hints) 
+9
source

Mr. Smith's answer is quite right. But for some reason you need to use the lowercase utf-8 instead of the uppercase utf-8 when encoding with ZXing . Or some scanners, such as Alipay, cannot read it.

 Hashtable hints = new Hashtable(); hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); 
+3
source

Source: https://habr.com/ru/post/1403029/


All Articles