Java two-dimensional code principle and the generation and decoding of two-dimensional codes implemented in Java

Source: Internet
Author: User
Tags mixed alphanumeric characters

QR code generation principle (i)

First, what is QR code

QR code is a kind of matrix two-dimensional code, developed by Denso (Japan Electric installation) company, standardized by JIS and ISO. The QR code looks in fact on many occasions already can be seen, I this still put a picture to show:

If this figure is decoded correctly, you should see my name and mailbox.

Second, the characteristics of QR code

When it comes to QR code, one is high speed reading (QR is the first letter from "Quick Response"), the experience of reading speed is derived from a software on my phone, like the code map posted above, through the camera from shooting to decoding to display content is about three seconds, the camera angle is not what the requirements;

Second, high capacity, high-density; In theory, the content can be stored 7,089 digits, 4,296 alphanumeric characters, 2,953 8-byte data and 1817 Chinese characters after compressing.

The third is to support error correction processing, error correction processing is relatively complex, at present, I do not have in-depth understanding, according to QR code standard documentation, QR Code error correction is divided into 4 levels, namely:

· Level L: The maximum 7% error can be corrected;

· Level M: The maximum 15% error can be corrected;

· Level Q: The maximum 25% error can be corrected;

· Level H: The maximum 30% error can be corrected;

Four is structured; seemingly irregular graphics, in fact, there is a strict definition of the region, the following figure is a pattern 2, version 1 QR chart structure (about QR code "mode", "version" will be introduced later):

In the matrix 21*21 above, the Black-and-white region is designated as a fixed position in the QR Code specification, known as the search graph (finder pattern) and the positioning graph (timing pattern). Image-seeking and positioning graphics help the decoding program to determine the coordinates of the specific symbols in the graph.

The yellow area is used to hold the encoded data content and the error-correcting information code.

A blue area that identifies the level of error correction (that is, levels L through H) and the so-called "Mask pattern", which is called "Formatting Information" (format information).

Five is the ability to expand. QR code structure append features, so that a QR code can be decomposed into multiple QR code, on the contrary, you can also combine multiple QR code data into a QR code.

Three, QR code mode and version

Previous versions of QR code (model) and version were mentioned. QR code is divided into Model1 and Model2 two modes, MODEL1 is the initial definition of QR, Model2 is the extension of Model1, the current use is more commonly Model2, all the instructions in this article are only for Model2.

The size of the QR chart is defined as version, and the version number is 1 through 40. Version 1 is a 21*21 matrix, with each additional version number, the size of the matrix is increased by 4 modules (module), so version 40 is a 177*177 matrix. (The higher the version, the more content you store, the more error-correcting ability).

Three, QR code support encoding content

QR codes support encoded content including pure digits, numeric and character mixed encodings, 8-bit bytecode and multibyte characters including Chinese characters. which

Number: Each three is compressed into a group of 10bit.

Alphanumeric mixing: Each two is a group, compressed into 11bit.

8bit byte data: No compression direct save.

Multibyte characters: Each character is compressed into 13bit.

QR Code Coding Principle II (Code)

Coding is the way to convert common numbers, characters, etc. into QR codes. Before you say specific coding, let's talk about the maximum capacity of the QR code.

One, Maximum capacity

The maximum capacity of a QR code depends on the version selected, the error-correcting level, and the encoding mode (mode: numbers, characters, multibyte characters, and so on). For example, the QR code with version 1 and error correction level Q can store 27 pure digits, or 17 alphanumeric mixed characters or 11 8bit byte data. If you want to store the same amount of content while increasing the level of error correction, you need to take a higher version. Version 1~9 data capacity, error-correcting code capacity is compared to the following table:

(version)

(Error correcting level)

(count of data code words)

count of EC code words

(numeric)

(alphanumeric)

8bit

1

L

19

7

41

25

17

M

16

10

34

20

14

Q

13

13

27

16

11

H

9

17

17

10

7

2

L

34

10

77

47

32

M

28

16

63

38

26

Q

22

22

48

29

20

H

16

28

34

20

14

3

L

55

15

127

77

53

M

44

26

101

61

42

Q

34

36

77

47

32

H

26

44

58

35

24

4

L

80

20

187

114

78

M

64

36

149

90

62

Q

48

52

111

67

46

H

36

64

82

50

34

5

L

108

26

255

154

106

M

86

48

202

122

84

Q

62

72

144

87

60

H

46

88

106

64

44

6

L

136

36

322

195

134

M

108

64

255

154

106

Q

76

96

175

108

74

H

60

112

139

84

58

7

L

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.