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

Laurence picture Laurence · Mar 23, 2012 · Viewed 13.4k times · Source

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?

Answer

Mister Smith picture Mister Smith · Mar 23, 2012

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)