The method of inserting picture in QR two-dimensional code _java

Source: Internet
Author: User

Insert picture in QR two-dimensional code

Two-dimensional code finally fire, now the streets and the size of the ads on the two-dimensional code tags are everywhere, and most of them are not simple two-dimensional code, but the middle of the two-dimensional icon of the two-dimensional code.

I did a previous use of Google Open source project zxing implementation of two-dimensional code, one-dimensional code encoding and decoding of the program and opened the source code (with C # Implementation of the barcode and two-dimensional code codec), today continue on this program based on the implementation of two-dimensional code between the small picture.

Background knowledge

QRCode used the code of NED-Solomon for error correction. For us, Reed-Solomon code has two very important features. First, it's an explicit system code, which means you can see the original information directly in the final code. As we encode "Hello World", we finally see "Hello World" and a few fault-tolerant codes followed by it. 2nd, Reed-Solomon's code can be "different or", a new Reed-Solomon code will be obtained when the results of two different de-Solomon codes are given, and the original code of the new code is the original two original code. If you want to know why these two features will be set up, see finite Field arithmetic and Reed-solomon coding.

QRCode

A pair of QRCode images will define unique descriptors to help people or computers recognize that they are a qrcode. This descriptor differs slightly from the size of the QRCode-the larger the QRCode image has more descriptors. But for people to identify, the most obvious feature is the picture of the four-point symbol is fixed, see such a four-point human instinct response: This is a qrcode.

(In fact, we can determine the degree of redundancy in the encoding by reading the two pixel points in the upper-left corner of the image.) The definition of black is 0, white is 1, then if you see 00 is the L-level redundancy, 01 is m,10 is q,11 is the highest H-level redundancy.

With the above work, we can easily know the location of the source code information in the image. Then by changing the source code information, you can change the pixel in the image so that it can be plotted in it. In spite of this, some of the following situations can make things more interesting.

I do the two-dimensional code insert Picture:

Before I gave you free to use the Zxing open source project transformed into a one or two-D code codec, but could not insert a picture. This time through a number of efforts to successfully insert the picture into two-dimensional code, and can encode and decode. The key to insert the picture is the adjustment of the two-dimensional code fault-tolerant coefficient, which is described in detail in the source code.

Interface:

To insert a picture in a two-dimensional code and to decode it normally, focus on the following two points:

1. The fault-tolerant coefficient of the two-dimension code should be high;

In a zxing project, a fault-tolerant coefficient can be set when a two-dimensional code is generated:

Set Encodehinttype.error_correction to ErrorCorrectionLevel.H

Constructing a two-dimensional code
        -coder Multiformatwriter mutiwriter = new Com.google.zxing.MultiFormatWriter ();
        Hashtable hint=new Hashtable ();
        Hint. ADD (Encodehinttype.character_set, "UTF-8");
        Hint. ADD (encodehinttype.error_correction,com.google.zxing.qrcode.decoder.errorcorrectionlevel.h);
        Generate two-dimensional code
        Bytematrix BM = Mutiwriter.encode (Txtmsg.text, Com.google.zxing.BarcodeFormat.QR_CODE, 300,hint);
        Bitmap img = BM. Tobitmap ();

2. The middle inserts the picture size and the position should be suitable;


If the middle picture is too large, covering up most of the two-dimensional code area, that must not, if too small, can not be personalized effect.

So much suitable, according to the characteristics of the QR code described in the previous article, the three squares of the corner is the data area, can not cover, only the middle and lower right corner of this area can cover, but not too big.

After testing, the middle small picture size of the two-dimensional code total width of 2/7 more appropriate, not only to meet the clarity of the picture, but also does not affect the two-dimensional code encryption data.

Small pictures are best positioned in the center, and shapes can be irregular.

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

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.