Maven
1 <dependency>2 <groupId>com.google.zxing</groupId>3 < Artifactid>core</artifactid>4 <version>3.3.3</version>5 </ Dependency>
Code
Import Com.google.zxing.barcodeformat;import Com.google.zxing.common.bitmatrix;import Com.google.zxing.qrcode.qrcodewriter;import Org.junit.test;import Javax.imageio.imageio;import Java.awt.*;import Java.awt.image.bufferedimage;import java.io.file;//test QR code generates public class Qrcodetest {@Test public void testgenerate ( ) throws Exception {Qrcodewriter writer = new Qrcodewriter (); int width = 400; int height = 400; Bitmatrix Bitmatrix = Writer.encode ("http://www.baidu.com", barcodeformat.qr_code, width, height); BufferedImage image = New BufferedImage (Bitmatrix.getwidth (), Bitmatrix.getheight (), BUFFEREDIMAGE.TYPE_3BYTE_BGR); for (int i = 0; i < width; i++) {for (int j = 0; j < height; J + +) {Image.setrgb (i,j, Bitmatrix.get (i,j)? Color.BLACK.getRGB (): Color.white.getRGB ()); }} File File = new file ("./test.jpg"); System.out.println (File.getabsolutepath ()); Imageio.write (iMage, "JPG", file); }}
If the Chinese is garbled, you can first urlencoder the content to be processed, become without the content of Chinese characters to call the method on it.
Java generates QR code (using Google's jar package)