Java and JS generate two-dimensional code

Source: Internet
Author: User

1. Java generates QR code

1.1 Dependent Jar package configuration (using Maven dependency)

1         <dependency> 2             <groupId>com.google.zxing</groupId> 3             <artifactid >core</artifactId> 4             <version>3.0.0</version> 5         </dependency > 6         <dependency> 7             <groupId>com.google.zxing</groupId>  8             <artifactId>javase</artifactId> 9             <version>3.0.0</version> Ten         </dependency>


1.2 Generate QR Code--zxing

1      Public Static voidCreateqrcode () {2         Try {3String content = "120605181003;HTTP://WWW.CNBLOGS.COM/JTMJX";4String Path = "D:/temp";5 6Multiformatwriter Multiformatwriter =NewMultiformatwriter ();7 8Map hints =NewHashMap ();9Hints.put (Encodehinttype.character_set, "UTF-8");TenBitmatrix Bitmatrix = multiformatwriter.encode (content, Barcodeformat.qr_code, 400, 400, hints); OneFile file1 =NewFile (Path, "Qrcode.jpg"); AMatrixtoimagewriter.writetofile (Bitmatrix, "JPG", file1); -  -System.out.println ("Successfully generated QR code"); the}Catch(Exception e) { - e.printstacktrace (); -         } -}

1.3 Parsing two-dimensional code--zxing

1      Public Static voidParseqrcode () {2         Try {3Multiformatreader Formatreader =NewMultiformatreader ();4String FilePath = "D:/temp/qrcode.jpg";5File File =NewFile (filePath);6BufferedImage image =imageio.read (file);7             ;8Luminancesource Source =NewBufferedimageluminancesource (image);9Binarizer Binarizer =NewHybridbinarizer (source);TenBinarybitmap Binarybitmap =NewBinarybitmap (binarizer); OneMap hints =NewHashMap (); AHints.put (Encodehinttype.character_set, "UTF-8"); -Result result =Formatreader.decode (Binarybitmap, hints); -  theSYSTEM.OUT.PRINTLN ("result =" +result.tostring ()); -System.out.println ("Resultformat =" +Result.getbarcodeformat ()); -System.out.println ("Resulttext =" +Result.gettext ()); -  +}Catch(Exception e) { - e.printstacktrace (); +         } A}
2. js generate two-dimensional code

2.1 Using Jquery-qrcode

Jquery-qrcode Features: Simple operation, small size, only 14k after compression, but does not support Chinese encoding.

Jquery.qrcode.min.js File Download path: http://files.cnblogs.com/files/qdwyg2013/jquery.qrcode.min.js

1<script type= "Text/javascript" src= "Http://cdn.staticfile.org/jquery/2.0.0/jquery.min.js" ></script>2<script type= "Text/javascript" src= ". /js/jquery.qrcode.min.js "></script>3<script>4         //Way One5         //$ (' #qrcode '). QRCode ("Http://www.cnblogs.com/xiyangbaixue");6         //Mode two7$ ("#qrcode"). QRCode ({8Render: "Table",//Table Mode9WIDTH:200,//widthTenHEIGHT:200,//Height OneText: "Www.baidu.com"//any Content A         }); -</script>

2.2 using QRCode

QRCode Features: Chinese-generated QR code scanning does not appear garbled, and you can choose which element to use to draw the QR code.

Qrcode.js File Download path: http://files.cnblogs.com/files/qdwyg2013/qrcode.js

1<script type= "Text/javascript" src= "Http://cdn.staticfile.org/jquery/2.0.0/jquery.min.js" ></script>2<script type= "Text/javascript" src= ". /js/qrcode.js "></script>3<script>4         //Way One5         //New QRCode (document.getElementById ("QRCode"), "Http://www.cnblogs.com/xiyangbaixue");6         //Mode two7         NewQRCode (document.getElementById ("QRCode"), {8Text: "Http://www.cnblogs.com/xiyangbaixue",9Width:50,TenHeight:50, OneBackground: "#ccc", AForeground: "Red" -         }); -</script>

Java and JS generate 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.