Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 545
Coding minion Avatar asked Mar 23 '12 08:03

Coding minion


People also ask

What is Zxing net?

ZXing.Net is a port of ZXing, an open-source, multi-format 1D/2D barcode image processing library originally implemented in Java. It has been ported by hand with a lot of optimizations and improvements.

What is Zxing library?

ZXing ("zebra crossing") is an open-source, multi-format 1D/2D barcode image processing library implemented in Java, with ports to other languages.


2 Answers

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)
like image 185
Mister Smith Avatar answered Sep 24 '22 10:09

Mister Smith


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");
like image 36
Landys Avatar answered Sep 22 '22 10:09

Landys