Implementation method of inserting picture into QR QR QR code

Insert picture into QR QR code

QR code is finally popular. Now QR code labels on commodity advertisements in streets and alleys can be seen everywhere, and most of them are not simple pure QR codes, but QR codes with personality icons in the middle.

I used to do a program to realize the encoding and decoding of two-dimensional code and one-dimensional code using Google's open source project zxing, and opened the source code (the bar code and two-dimensional code codec implemented in c#). Today, I continue to realize the addition of small pictures in the middle of two-dimensional code on the basis of this program.

background knowledge

QRcode uses Reed Solomon code for error correction. For us, Reed Solomon coding has two very important features. First, it is an explicit system code, that is, you can directly see the original information in the final code. For example, when we code "Hello world", we finally see "Hello world" and several fault-tolerant codes followed by it. Second, Reed Solomon code can be "XOR". After XOR operation of the results obtained from two different Reed Solomon codes, a new Reed Solomon code will be obtained, and the original code of the new code is the XOR of the original two original codes. If you want to know why these two features work, please see finish field arithmetic and Reed Solomon coding

QRcode

A QRcode image defines some unique descriptors to help people or computers identify themselves as a QRcode. This descriptor varies slightly with the size of the QRcode -- the larger the QRcode image, the more descriptors it has. However, for human recognition, the most obvious feature is that the symbols at the four corners of the picture are fixed. Seeing such four corners, humans instinctively respond: This is a QRcode.

(in fact, we can judge the redundancy degree of coding by reading the two pixel points in the top left corner of the image. Define Black as 0 and white as 1. If you see 00, it is L-level redundancy, 01 is m, 10 is Q, and 11 is the highest h-level redundancy.

With the above work, we can easily know the position of the original code information in the image. Then by changing their original code information, you can change the pixels in the image so that you can draw in it. Nevertheless, the following situations can make things more interesting.

The QR code I made is inserted into the picture:

Before, I provided you with a QR code codec transformed from zxing open source project for free, but failed to insert pictures. This time, after some efforts, the picture is successfully inserted into the QR code, and can be encoded and decoded. The key to inserting pictures is the adjustment of QR code fault tolerance coefficient, which is described in detail in the source code.

Interface:

To insert pictures into the QR code and decode them normally, pay attention to the following two points:

1. Set the fault tolerance coefficient of QR code to be high;

In zxing project, fault tolerance coefficient can be set when QR code is generated:

Encodehinttype ERROR_ Correction is set to errorcorrectionlevel H

2. The size and position of the picture inserted in the middle shall be appropriate;

If the middle picture is too large and covers most of the area of the QR code, it certainly can't. If it is too small, it won't have a personalized effect.

How much is appropriate? According to the characteristics of QR code described above, the three corners with blocks are data areas, which cannot be covered. Only the middle and lower right corners can be covered, but they should not be too large.

After testing, the middle small picture size accounts for 2 / 7 of the total width of the QR code, which not only meets the definition of the picture, but also does not affect the encrypted data of the QR code.

Small pictures are best placed in the middle, and the shape can be irregular.

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>