The specific code below, as a novice, look forward to communicating with you:
1 ImportJava.awt.Color; 2 ImportJava.awt.Graphics2D; 3 ImportJava.awt.image.BufferedImage; 4 ImportJava.io.File; 5 6 ImportJavax.imageio.ImageIO; 7 8 ImportCom.swetake.util.Qrcode;9 Public classQrcodeencoderhandler {Ten /** One * Generate QR Code (qrcode) Pictures A * @paramcontent - * @paramImgpath - */ the Public voidEncoderqrcode (String content,string imgpath) { - Try{ -QRCode Qrcodehandler =NewQRCode (); -Qrcodehandler.setqrcodeerrorcorrect (' M '); +Qrcodehandler.setqrcodeencodemode (' B '); -Qrcodehandler.setqrcodeversion (7); + A System.out.println (content); at byte[] contentbytes = Content.getbytes ("Utf-8"); - -BufferedImage bufimg =NewBufferedImage (140, 140, - Bufferedimage.type_int_rgb); - -Graphics2D GS =Bufimg.creategraphics (); in - Gs.setbackground (Color.White); toGs.clearrect (0, 0,30000,30000); + - //set Image Color > BLACK theGs.setcolor (NewColor (0,0,0,255)); * $ //setting offset does not set may cause parsing errorsPanax Notoginseng intPixoff = 2; - //output content > QR Code the if(Contentbytes.length > 0 && contentbytes.length < 120) { + Boolean[] Codeout =Qrcodehandler.calqrcode (contentbytes); A for(inti = 0; i < codeout.length; i++) { the for(intj = 0; J < Codeout.length; J + +) { + if(Codeout[j][i]) { -Gs.fillrect (J * 3 + Pixoff, I * 3 + Pixoff, 3, 3); $ } $ } - } -}Else { theSystem.err.println ("qrcode content bytes Length =" -+ Contentbytes.length + "not in [0,120]."); Wuyi } the - Gs.dispose (); Wu Bufimg.flush (); - AboutFile Imgfile =NewFile (Imgpath); $ - //generate two-dimensional code QRCode pictures -Imageio.write (bufimg, "PNG", Imgfile); -}Catch(Exception e) { A //Todo:handle Exception + e.printstacktrace (); the } - } $ Public Static voidMain (string[] args) { theString Imgpath = "D://michael.jpg"; the theString content = "Name: * *" the+ "\n\r Tel: 135********" -+ "\n\remail:******[email protected]" + "\n\remail2:******@163.com" + "\N\RQQ:* * * * * * * * * * *; in theQrcodeencoderhandler handler =NewQrcodeencoderhandler (); the Handler.encoderqrcode (content, Imgpath); About theSYSTEM.OUT.PRINTLN ("Encoder qrcode Success"); the } the}
Java generates two-dimensional code