1: Using Swetakeqrcode to generate two-dimensional code in a Java project
http://swetake.com/qr/
or Http://sourceforge.jp/projects/qrcode/downloads/28391/qrcode.zip.
This was written by the Japanese and generated by our common square QR code.
Can be in Chinese
such as: 5677777GHJJJJJ
2: Use barcode4j to generate barcodes and QR codes
BARCODE4J Website: http://sourceforge.net/projects/barcode4j/
BARCODE4J is a two-dimensional code generation algorithm that uses Datamatrix to support the QR algorithm
Datamatrix is the European and American Standard, the QR is the Japanese standard,
Barcode4j are generally generated as rectangles.
such as: 88777alec000yan
This blog is very clear about this aspect:
http://baijinshan.iteye.com/blog/1004554
3:zxing
4:google Chart API There is a way to implement a two-dimensional code
Use this API to implement with Google AppEngine.
5:js generate two-dimensional code
Using Jquery-qrcode to generate two-dimensional code
First of all, Jquery-qrcode, this open source tripartite library (can be obtained from Https://github.com/jeromeetienne/jquery-qrcode),
Qrcode.js is the core class to realize the computation of two-dimensional code data,
Jquery.qrcode.js is to use it in a jquery way, using it to achieve graphics rendering, is actually drawing (support canvas and table two ways)
The main features supported are:
JS Code:
- Text: "Https://github.com/jeromeetienne/jquery-qrcode"//Set two-dimensional code content
JS Code:
- Render: "Canvas",//Set rendering mode
- width:256, //Set width
- height:256, //Set height
- Typenumber:-1, //Calculation mode
- Correctlevel:qrerrorcorrectlevel.h,//error correction level
- Background: "#ffffff",//Background color
- Foreground: "#000000" //Foreground color
The way to use it is very simple
JS Code:
- JQuery (' #output '). QRCode ({width:200,height:200,correctlevel:0,text:content});
After a simple practice,
Using the canvas to render the performance is very good, but if you use Table mode, performance is not ideal, especially IE9 below the browser, so you need to optimize the way you render table, here is not described in detail.
In fact, the above JS has a small drawback, that is, the default does not support Chinese.
This is related to the mechanism of JS, Jquery-qrcode This library is using charCodeAt () This way to encode the conversion,
And this method by default will get its Unicode encoding, the general decoder is the use of UTF-8, iso-8859-1 and other ways,
English is no problem, if it is Chinese, the general Unicode is UTF-16 implementation, the length of 2 bits, and UTF-8 encoding is 3 bits, so that the codec of the two-dimensional code does not match.
The solution, of course, is to convert the string to UTF-8 before the QR code is encoded, as follows:
- function Utf16to8 (str) {
- var out, I, Len, C;
- out = "";
- len = str.length;
- For (i = 0; i < len; i++) {
- c = str.charcodeat (i);
- if ((C >= 0x0001) && (c <= 0x007F)) {
- Out + = Str.charat (i);
- } Else if (C > 0x07ff) {
- Out + = String.fromCharCode (0xE0 | ((c >> b) & 0x0F));
- Out + = String.fromCharCode (0x80 | ((c >> 6) & 0x3F));
- Out + = String.fromCharCode (0x80 | ((c >> 0) & 0x3F));
- } Else {
- Out + = String.fromCharCode (0xC0 | ((c >> 6) & 0x1F));
- Out + = String.fromCharCode (0x80 | ((c >> 0) & 0x3F));
- }
- }
- return out;
- }
Zxing This is Google's
Http://code.google.com/p/zxing/downloads/list
Java code:
- Import Java.io.File;
- Import java.util.Hashtable;
- Import Com.google.zxing.BarcodeFormat;
- Import Com.google.zxing.EncodeHintType;
- Import Com.google.zxing.MultiFormatWriter;
- Import Com.google.zxing.client.j2se.MatrixToImageWriter;
- Import Com.google.zxing.common.BitMatrix;
- Import Com.google.zxing.qrcode.QRCodeWriter;
- Public class Qrcodeevents {
- public static void Main (String []args)throws exception{
- String text = "Hello";
- int width = 100;
- int height = 100;
- String format = "PNG";
- Hashtable hints= New Hashtable ();
- Hints.put (Encodehinttype.character_set, "Utf-8");
- Bitmatrix Bitmatrix = new Multiformatwriter (). Encode (text, Barcodeformat.qr_code, width, height,hints);
- File OutputFile = new File ("New.png");
- Matrixtoimagewriter.writetofile (Bitmatrix, format, outputFile);
- }
- }
Two-dimensional code, also known as two-dimensional barcode, two-dimensional barcode was first invented in Japan, it is a certain geometry according to a certain pattern in the plane (two-dimensional direction) distribution of black and white graphics data symbol information, in the code to skillfully use the structure of the computer's internal logic based on the "0", "1" bitstream concept, A number of geometric shapes corresponding to the binary are used to represent the literal numerical information, which is automatically read by the image input device or photoelectric scanning device to realize automatic information processing. It has some common features of barcode technology: Each code system has its specific character set, each character occupies a certain width, and has certain checking function. At the same time, it also has the features of automatic recognition of different lines, and the processing of the change of graphics rotation.
1.java this way. Generate two-dimensional code there are many developed jar packages such as zxing,qrcode.q the former is Google development of the latter is small Japan developed, here I use the zxing development package to get
2. Download the Zxing Development Kit first, here is only the core of the jar package
3. A class is also required to develop with zxing, the code is as follows
Package org.lxh; Import Com.google.zxing.common.BitMatrix; Import Javax.imageio.ImageIO; Import Java.io.File; Import Java.io.OutputStream; Import java.io.IOException; Import Java.awt.image.BufferedImage; Public final class Matrixtoimagewriter {private static final int BLACK = 0xff000000; private static final int white = 0xFFFFFFFF; Private Matrixtoimagewriter () {} public static bufferedimage Tobufferedimage (Bitmatrix matrix) { int width = matrix.getwidth (); int height = matrix.getheight (); BufferedImage image = new BufferedImage (width, height, bufferedimage.type_int_rgb); for (int x = 0; x < width; + +) {for (int y = 0; y < height; y++) {Image.setrgb (x, Y, MA Trix.get (x, y)? Black:white); }} return image; } public static void WriteToFile (Bitmatrix matrix, String format, file file) throws IOException {bufferedimage ima GE = tobufferedimage (matrix); if (! Imageio.write (image, format, file)) {throw new IOException ("Could not write an image of format" + Format + " To "+ file); }} public static void WriteToStream (Bitmatrix matrix, String format, OutputStream stream) Throws IOException {bufferedimage image = Tobufferedimage (matrix); if (! Imageio.write (image, format, stream)) {throw new IOException ("Could not write an image of format" + format); } } }
4. Generate a QR code using the class above
Package org.lxh; Import Java.io.File; Import java.util.Hashtable; Import Com.google.zxing.BarcodeFormat; Import Com.google.zxing.EncodeHintType; Import Com.google.zxing.MultiFormatWriter; Import com.google.zxing.WriterException; Import Com.google.zxing.common.BitMatrix; public class Test {/** * @param args * @throws Exception */Public St atic void Main (string[] args) throws Exception {String text = "http://www.baidu.com"; int width = 300; int height = 300; The picture format of the QR code, String formatted = "GIF"; Hashtable hints = new Hashtable (); The content is encoded using Hints.put (Encodehinttype.character_set, "utf-8"); Bitmatrix Bitmatrix = new Multiformatwriter (). Encode (text, barcodeformat.qr_code, width, height, hint s); Generate two-dimensional code File OutputFile = New File ("D:" +file.separator+ "new.gif"); Matrixtoimagewriter.writetofile (Bitmatrix, format, outputFile); } }
Text is the content of the two-dimensional code here can make ordinary text can also be links, very simple finally the resulting QR code image to everyone
Java implementation of two-dimensional code generation of several methods