Java uses QRCode to generate two-dimensional code images or base64 strings

Source: Internet
Author: User
Tags base64

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

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.