How do I encode characters using UTF-8 in a QR code using Zxing project?

16,068

Solution 1

The proper way of doing this is using hints:

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

Then call this version of encode in QRCodeWriter class:

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

Solution 2

Mister Smith's answer is quite right. But somehow you need to use the lowercase utf-8 instead of 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");
Share:
16,068
Coding minion
Author by

Coding minion

Hello World!

Updated on June 06, 2022

Comments

  • Coding minion
    Coding minion almost 2 years

    Zxing Project is a famous open-source, multi-format 1D/2D barcode image processing library implemented in Java, with ports to other languages. But I believe there are somebody have the same problem just like me: I can't Encode UTF-8 characters in a Qrcode.

    How do I encode characters using UTF-8 in a QR code using Zxing project?