Java-generated two-dimensional code demo

Source: Internet
Author: User
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.

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.