PackageCom.aig.ecompass.ecard;ImportJava.awt.image.BufferedImage;ImportJava.io.File;Importjava.io.IOException;ImportJava.util.HashMap;ImportJava.util.Map;ImportJavax.imageio.ImageIO;ImportCom.google.zxing.BarcodeFormat;ImportCom.google.zxing.EncodeHintType;ImportCom.google.zxing.MultiFormatWriter;ImportCom.google.zxing.common.BitMatrix; Public classEcardqrcode {Private Static Final intBLACK = 0xff000000;Private Static Final intWhite = 0xFFFFFFFF; Public Static voidCreateqrcode () {//WebSphere application Server v8.0 at localhostString content = "AIA technology Shared Service,ecard QRCode"; String Path= "d:/"; String suffix= "png";Try{multiformatwriter Multiformatwriter=NewMultiformatwriter (); Map hints=NewHashMap (); Hints.put (Encodehinttype.character_set,"UTF-8"); Bitmatrix Bitmatrix= Multiformatwriter.encode (content, Barcodeformat.qr_code, 400, 400, hints); File File=NewFile (Path, "Ecard.png");intwidth =bitmatrix.getwidth ();intHeight =bitmatrix.getheight (); BufferedImage Image=Newbufferedimage (width, height, bufferedimage.type_int_rgb); for(intx = 0; x < width; X + +) { for(inty = 0; Y < height; y++) {Image.setrgb (x, Y, Bitmatrix.get (x, y)?black:white);}}if(!imageio.write (image, suffix, file)) {Throw NewIOException ("Could not write a image of format" + suffix + "to" +file);}} Catch(Exception e) {//TODO auto-generated Catch blocke.printstacktrace ();}} Public Static voidMain (string[] args) {Createqrcode ();}}
Using Zxing's Core.jar package, zxing is the Google Open source package. Generate a QR code.
Two-dimensional code QRCode