In the age of the Internet of Things, the QR code is a very important thing, now no matter what things have to make a two-dimensional code sign, lest the outdated, the policeman did not use two-dimensional code recognition. Perhaps one day zoning card or hukou will be used to identify the two-dimensional code. Today's whim, see others have added two-dimensional code for their blog, I also want to make a test.
Mainly used to achieve two points:
1. Generate the QR code of any text.
2. Add an image to the middle of the QR code.
First we have to download the Zxing.jar package, I use the 3.0 version of the core package
: Now you have migrated to Github:https://github.com/zxing/zxing/wiki/getting-started-developing, and of course you can download the jar package from the MAVEN repository:/http Central.maven.org/maven2/com/google/zxing/core/
Build a test project based on Zxing. Generate two-dimensional code
The key code is: Bufferedimageluminancesource.java and Qrcodeutil.java, where the main method of the test is in Qrcodeutil.java.
Create a QR code with no logo
Public Static void Main (string[] args) throws Exception { "http://www.yihaomen.com"; "" " C:/barcode " true ); }
Run this test method, generated QR code without logo, the style is as follows:
I'm interested in scanning with a cellphone.
Create a QR code with logo
Logo can be used with their own avatar, or a picture of their favorite can be, using the following code
Public Static void Main (string[] args) throws Exception { "http://www.yihaomen.com"; " c:/me.jpg " " C:/barcode " true ); }
The only difference is that on the basis of the previous designation of the address of the logo, the test is used in the C-drive picture file
Scan with a mobile phone, can appear to appear in the text, click on to enter their own site, looks good, the entire source code, provided in the download test:
Java Barcode Sample
This article is from: http://www.yihaomen.com/, the original address: http://www.yihaomen.com/article/java/491.htm, thank the original author to share.
Example of generating a QR code for your website in Java