Zxing This is Google's
Http://code.google.com/p/zxing/downloads/list
Two-dimensional code source case
Packagecom.utils;ImportJava.awt.image.BufferedImage;ImportJava.awt.image.DataBufferByte;ImportJava.io.File;Importjava.io.IOException;Importjava.util.Date;Importjava.util.Hashtable;ImportJavax.imageio.ImageIO;ImportCom.google.zxing.BarcodeFormat;ImportCom.google.zxing.EncodeHintType;ImportCom.google.zxing.MultiFormatWriter;ImportCom.google.zxing.common.BitMatrix; Public classUtilsqrcode {Private Static Final intBLACK = 0xff000000; Private Static Final intWhite = 0xFFFFFFFF; /** * @paramargs*/ Public Static voidMain (string[] args) {File file=NewFile ("c:\\users\\huage\\desktop\\ picture \ \" +NewDate (). GetTime () + ". png"); Encode ("Http://www.baidu.com", File, Barcodeformat.qr_code, 200, 200); } /** * @paramContents *@paramfile *@paramformat *@paramWidth *@paramHeight*/ Public Static voidEncode (String contents, file file, Barcodeformat format,intWidthintheight) { Try{Contents=NewString (Contents.getbytes ("UTF-8"), "Iso-8859-1"); Hashtable<encodehinttype, object> hints =NewHashtable<encodehinttype, object>(); Hints.put (Encodehinttype.character_set,"Utf-8"); Hints.put (Encodehinttype.margin,1); Bitmatrix Bitmatrix=NewMultiformatwriter (). Encode (contents, format, width, height,hints); BufferedImage Image=tobufferedimage (Bitmatrix); WriteToFile (Image,"PNG", file); } Catch(Exception e) {e.printstacktrace (); } } Public Static byte[] imgtobytes (bufferedimage image) {if(Image = =NULL)return New byte[0]; byte[] data =((DataBufferByte) Image.getdata (). Getdatabuffer ()). GetData (); returndata; } Public Static voidWriteToFile (bufferedimage image, String format, file file)throwsIOException {if(Image = =NULL|| File = =NULL)return; Imageio.write (image, format, file); } Public Staticbufferedimage tobufferedimage (Bitmatrix matrix) {intwidth =matrix.getwidth (); intHeight =matrix.getheight (); BufferedImage Image=Newbufferedimage (width, height, bufferedimage.type_int_argb); for(intx = 0; x < width; X + +) { for(inty = 0; Y < height; y++) {Image.setrgb (x, Y, Matrix.get (x, y)==true?black:white); } } returnimage; }}
java-Two-dimensional code to write zxing