In the era of the Internet of things, two-dimensional code is a very important thing, and now no matter what things must be a two-dimensional code signs, lest outdated, the cops did not use two-dimensional code to identify. Perhaps one day zoning card or hukou will be used to identify the two-dimensional code. Today's whim, see others for their blog added two-dimensional code, I also want to do a test.
Mainly used to achieve two points:
1. Generate a two-dimensional code of any text.
2. Add an image to the middle of a two-dimensional code.
First we have to download the Zxing.jar package, I'm here with the 3.0 version of the core package
Download Address: 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.
generate a two-dimensional code with no logo
public static void Main (string[] args) throws Exception {
String text = "http://www.yihaomen.com";
Qrcodeutil.encode (Text, "", "C:/barcode", True);
}
Run this test method, the generated two-dimensional code without logo, the style is as follows:
I'd be interested in a cellphone scan.
generate a two-dimensional code with logo
Logo can use their own avatar, or a picture of their favorite can be, using the following code
public static void Main (string[] args) throws Exception {
String text = "http://www.yihaomen.com";
Qrcodeutil.encode (text, "C:/me.jpg", "C:/barcode", true);
}
The only difference is that, on the basis of the previous designation of the address of the logo, where the test using the C-disk picture file
With a mobile phone scan, can appear to appear text, click on the website to enter their own, looks good, the entire source code, provided in the download test:
Java Barcode Sample
This article originates from: http://www.yihaomen.com/, original address: http://www.yihaomen.com/article/java/491.htm, thanks the original author to share.