Generate a QR code image or base64 format string by passing in a string
1 Public StaticString Barcode2base64 (String msg)throwsexception{2QRCode x =NewQRCode ();3 //N Represents the number, a represents a-z,b for other characters4X.setqrcodeencodemode (' B ');5 //set error correction level6X.setqrcodeerrorcorrect (' M ');7 //Set version number (1-40)8X.setqrcodeversion (7);9 Ten intwidth = 67+12* (7-1); One intHeight = 67+12* (7-1); A intPixoff = 2;//Offset Amount - -BufferedImage BufferedImage =Newbufferedimage (width, height, bufferedimage.type_int_rgb); theGraphics2D GS =bufferedimage.creategraphics (); - Gs.setbackground (color.white); - Gs.setcolor (color.black); -Gs.clearrect (0, 0, width, height); + - byte[] D = msg.getbytes ("UTF-8"); + if(d.length>0&&d.length<120){ A Boolean[] s =X.calqrcode (d); at for(inti=0;i<s.length;i++){ - for(intj=0;j<s.length;j++){ - if(S[j][i]) { -Gs.fillrect (J*3+pixoff, I*3+pixoff, 3, 3); - } - } in } - } to //Encrypt + gs.dispose (); - Bufferedimage.flush (); theBytearrayoutputstream BOS =NewBytearrayoutputstream (); *Imageio.write (BufferedImage, "BMP", BOS);//BOS can be a file output stream, written here to byte stream $ //EncryptPanax NotoginsengBase64encoder encoder =NewBase64encoder (); - returnEncoder.encode (Bos.tobytearray ()); the}
Java uses QRCode to generate a two-dimensional code picture or base64 string