Java generates two-dimensional code

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.