First you need to download the Google.zxing Jar pack
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; public class Testqrcode {/** * @param args */public static void main (string[] args) {String str = "Hu Hansan: Male motto: H
Ard Word pays off tiandaochouqin ... ";//two-dimensional code content String Path =" e:\\ My two-dimensional Code \\hhs3.png ";
Bitmatrix Bytematrix;
try {hashtable<encodehinttype, integer> hints = new Hashtable<encodehinttype, integer> (); Hints.put (Encodehinttype.margin, 1); Set the size of a two-dimensional code blank border 1-4,1 is the minimum 4 is the default GB Bytematrix = new Multiformatwriter (). Encode (New String (Str.getbytes ("UTF-8"), "iso-885
9-1 "), Barcodeformat.qr_code, 200,hints);
File File = new file (path);
Matrixtoimagewriter.writetofile (Bytematrix, "PNG", file);
catch (Exception e) {e.printstacktrace (); }
}
}
Generated two-dimensional code ...