Android app-QR code generation (QR code) (1)

Source: Internet
Author: User

QR code definition:

QR code 2-dimen1_bar code) records the data symbol information by using a specific ry that is distributed in two-dimensional directions of the plane according to a certain pattern.

In many types of two-dimensional bar codes, the commonly used Code systems include Data Matrix, Maxi Code, Aztec, QR Code, QR Code, Vericode 417, Ultracode, Code 49, and Code 16K.
1. Stacked/row-arranged two-dimensional Barcode, Such as Code 16 K, Code 49, and ipv417.

2. Matrix QR codeThe most popular is qr code.
The name of a QR code is relative to a one-dimensional code. For example, the previous barcode is a one-dimensional code. It has the following advantages: the two-dimensional code stores a larger amount of data and can contain numbers and characters, and Chinese text and other mixed content; some fault tolerance can be read normally after some damage); high space utilization.

QR code principles:

Quick-Response code is a widely used QR code with fast decoding speed.
It can store multiple types


For example, the basic structure of a qrcode, where:
Location Detection Image, Location Detection Image separator, and positioning image: used to locate the QR code. For each QR code, the location is fixed, but the size and specifications may vary;
Calibration image: the specification is determined, and the quantity and position of the correction image are also determined;
Format information: indicates the error correction level for modifying the QR code, which can be L, M, Q, and H;
Version information: the type of the QR code. The matrix of a total of 40 types of QR code is generally black and white), from 21x21 version 1) to 177x177 version 40 ), each version adds four modules to each side of the previous version;
Data and Error Correction Code: the information of the actually saved QR code, and the error code is used to correct the error caused by the damage of the QR code ).

Brief Encoding Process:
1. Data Analysis:Determine the encoding character type and convert it to a symbolic character based on the corresponding character set. Select the error correction level. The higher the error correction level, the smaller the actual data capacity.

2. Data Encoding:Converts a data character to a bitstream. Each 8-bit code word forms a data codeword sequence. In fact, the data content of the QR code is known as the data code sequence.

Data can be encoded in one mode for more efficient decoding, for example, for data: 01234567 encoding version 1-H ),
1) group: 012 345 67

2) convert to binary:

012 → 0000001100

345 → 0101011001
67 → 1000011
3) Conversion sequence: 0000001100 0101011001 1000011
4) convert the number of characters to binary: 8 to 0000001000
5) Add the mode indicator number) 0000001000 0000001100 0101011001 1000011
For letters, Chinese characters, and Japanese, only the group mode and mode are different. The basic methods are the same.

3. Error Correction Code:Block the above code sequence as needed, generate an error correction code field based on the error correction level and the code segment, and add the code to the data code sequence to form a new sequence.

When the two-dimensional code specifications and error correction levels are determined, the total number of characters that can be accommodated by the two-dimensional code and the number of characters in the Error Correction Code are also determined. For example, in version 10, when the error correction level is H, A total of 346 code words are supported, including 224 error correction code words.
That is to say, about 1/3 of the Code in the QR code area is redundant. For these 224 error codes, it can correct 112 replacement errors, such as black and white inversion) or 224 data read errors cannot be read or decoded ),
The error correction capacity is 112/346 = 32.4%.
4. Construct final data information:Under the condition that the specifications are determined, place the sequence generated above in order as a chunk.
Data is segmented according to regulations, and each block is calculated to obtain the corresponding block of the Error Correction Code. The block of the Error Correction Code form a sequence in order and is added to the back of the original data code sequence.
For example, D1, D12, D23, D35, D2, D13, D24, D36 ,... d11, D22, D33, D45, D34, D46, E1, E23, E45, E67, E2, E24, E46, E68 ,...

Constructor: puts the probe image, separator, positioning image, correction image, and code module into the matrix.

Fill in the complete sequence above to the area of the QR code matrix of the corresponding specification.

6. Mask:The hidden image is used in the Encoding Area of the symbol, so that the dark and light-colored black and white areas in the QR code image can be evenly distributed.
7. Format and version information:Enter the format and version information in the corresponding region.
Both versions 7-40 contain version information, and all versions without version information are 0. The two locations on the QR Code contain version information, which is redundant.
The version information is 18 bits in total, with a 6x3 matrix. The data in six bits is, for example, version 8, the data bit information is 001000, And the next 12 bits are error correction bits.

QR codes can be seen everywhere now. using Android code to generate a QR code based on the input string is actually very simple. You need to reference a Google open-source package-ZXing.

The following example contains the generation and resolution of the barcode and QR code. The following describes the generation of the QR code.

First, the implementation is given:

To generate a QR code, follow these steps:

1. First, enter the string content to be generated in the edit box.

2. click the button below

3. The ImageView control at the bottom of the button displays the generated QR code

The next page will show you the specific code and distribution source 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.