Several methods of two-dimensional code generation in Java (recommended)
Several methods of 2D code generation in Java are as follows:
1: Using swetakeqrcode to generate QR code in Java project
http://swetake.com/qr/ Download address
Or http://sourceforge.jp/projects/qrcode/downloads/28391/qrcode.zip
This is written by the Japanese. It generates our common square QR code
Can use Chinese
For example: 5677777ghjj
2: Barcodes and QR codes are generated using barcode4j
Barcode4j website: http://sourceforge.NET/projects/barcode4j/
Barcode4j is a QR code generation algorithm using DataMatrix, which supports QR
DataMatrix is the European and American Standard and QR is the Japanese standard,
Barcode4j is generally rectangular
For example: 88777alec000yan
3:zxing
Zxing this is from Google
Download address: http://code.google.com/p/zxing/downloads/list
Java code:
4: The Google chart API has a way to implement QR codes
Using this API, it is implemented using Google App Engine.
5: JS generate QR code
Using jQuery QRcode to generate QR code
Let's briefly talk about jQuery QRcode, an open-source third-party library (available from https://github.com/jeromeetienne/jquery-qrcode Get),
qrcode. JS is the core class to realize QR code data calculation,
jquery. qrcode. JS encapsulates it in jQuery mode and uses it to realize graphics rendering. In fact, it is drawing (supports canvas and table)
The supported functions mainly include:
JS code:
JS code:
It is very simple to use
JS code:
After simple practice,
The rendering performance using canvas is very good, but if you use table, the performance is not ideal, especially for browsers below IE9, so you need to optimize the rendering method of table by yourself, which will not be described in detail here.
In fact, the above JS has a small disadvantage, that is, it does not support Chinese by default.
This is related to the mechanism of JS. The jQuery QRcode library adopts the method of charcodeat () for encoding conversion,
This method will obtain its Unicode code by default. Generally, the decoder adopts UTF-8, iso-8859-1 and other methods,
There is no problem with English. If it is Chinese, Unicode is generally implemented in utf-16, with a length of 2 bits, while UTF-8 coding is 3 bits, so the encoding and decoding of QR code does not match.
Of course, the solution is to convert the string into UTF-8 before QR code coding. The specific code is as follows:
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.