Java SAO operation--Generate QR Code

Source: Internet
Author: User
Tags response code string format

For a long time did not publish a blog, today sent a Java tool class, suddenly found that the draft box unexpectedly has the previous inventory, one-time hair!!!

Catalogue 1. QR code concept 2. development History of QR code 3. Two-dimensional code classification 4. Two-dimensional code advantages and disadvantages 5.QR Code

1. Two-dimensional code, also known as two-dimensional bar code (2-dimensional bar code) is a certain geometric pattern in the plane (two-dimensional code) distribution of black-and-white graphics record data symbol information graphics.

2 QR code development History

1.20 century , John Ke Mende to realize the automatic sorting method of postal documents,

2.1949 The first barcode patent invented by the United States of America, Benisilve,

3.1959 year Gira de Feiser applied for a patent with a barcode to represent the number,

4.60 years Silvonia invented a barcode system and successfully applied it in the North American railway system,

In the 5.70 era,UPC codes (Universal Product code) were widely used in North American supermarkets,

6.1988 China has set up a Chinese goods coding center, The new era has not developed a two-dimensional code,

7.1997 year to year to determine the national standard

3. Two-dimensional code classification

1. One-dimensional bar code is a set of different weights, black and white ( or color ) of the alternating bar, empty and its corresponding characters ( Digital Letters ) made up of tags, i.e. traditional barcodes.

2. Two-dimensional barcode is to use a certain geometry according to a certain pattern in the plane (two-dimensional code on the distribution of bars, space graphics to record data symbol information

Two-dimensional barcode also has many different code systems, in terms of code encoding principle, usually divided into three kinds of
type :
1. Linear stacking two-dimensional code

Coding principle: based on a one-dimensional barcode, stacked into two or more rows as needed.


2. Matrix Two-dimensional code

in a rectangular space through the black, white pixels in the matrix of different distributions encoded by the Advent of the binary "1" point does not appear to represent the binary "0"


3. Postal Code

postal code is encoded by different lengths of bars, mainly for message encoding ,
POSTNET,
BPO 4-state.

4. Two-dimensional code advantages and disadvantages

5. QR Code

The current popular three-nation standard:

PDE417: Chinese is not supported

DM: Patent not disclosed, need to pay patent fee

QR Code: Patent Open, support Chinese

QR code , compared with other two-dimensional code, has the advantage of fast reading speed, large data size, and small space-occupying.

QR code is a matrix two-dimensional code symbol number developed by Nippon Denso Company in 1994 , the full name is Quick Response code .

Error correction capability

L level : approximately error-correcting 7% m level : approximately error-correcting 15% q level : approximately error-correcting 25% h level : approximately error-correcting 30%

6. Two-dimensional code production: Java language development

First introduce the Zxing jar package

Jar Package: Link:https://pan.baidu.com/s/1GzjQOqWhZYPsL0uzf569dw Password:kril

Detailed Operation:

 PackageCn.code;ImportJava.io.File;ImportJava.nio.file.Path;ImportJava.util.HashMap;ImportCom.google.zxing.BarcodeFormat;ImportCom.google.zxing.EncodeHintType;ImportCom.google.zxing.MultiFormatWriter;ImportCom.google.zxing.client.j2se.MatrixToImageWriter;ImportCom.google.zxing.common.BitMatrix;ImportCom.google.zxing.qrcode.decoder.ErrorCorrectionLevel;/** *  * @author: Cat on the room * * @time: 11:38:45 * * @ Blog Address:https://www.cnblogs.com/lsy131479/* Generate two-dimensional code*/ Public classZxing { Public Static voidMain (string[] args) {Zxing Zxing=NewZxing (); //parameters: Two-dimensional code content and generation path        if(Zxing.orcode ("https://www.cnblogs.com/lsy131479/", "f:\\1.jpg") {System.out.println ("OK, success"); } Else{System.out.println ("No, Failure"); }    }    Private BooleanOrcode (string content, string path) {/** Width and height of the picture*/        intwidth = 300; intHeight = 300; //the format of the pictureString format = "png"; //Two-dimensional code content//String content = "Hello,word"; //define the parameters of the QR codeHashMap hints =NewHashMap (); //defining character Set encoding formatsHints.put (Encodehinttype.character_set, "Utf-8"); //error correction level L > M > Q > H Error Correction the higher the ability to store less, generally using Mhints.put (encodehinttype.error_correction, ERRORCORRECTIONLEVEL.M); //Setting picture MarginsHints.put (Encodehinttype.margin, 2); Try {            //Final Build parameter list (1. Contents 2. Format 3. Width 4. Height 5. Two d code parameter)Bitmatrix Bitmatrix =NewMultiformatwriter (). Encode (content, barcodeformat.qr_code, width, height, hints); //write to localPath file =NewFile (path). Topath ();            Matrixtoimagewriter.writetopath (Bitmatrix, format, file); return true; } Catch(Exception e) {//TODO auto-generated Catch blockE.printstacktrace (); return false; }    }}

QR code generation There are other ways to generate, today will not be explained here, if interested can focus on the author, follow-up will continue out of the tutorial

Other ways:

   1.or code Generation and parsing

2.jquery-qrcode Generation and analysis

Java SAO operation--Generate QR Code

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.