Java QR code tool class, with a LOGO in the middle, very powerful, java tool class logo
Jar package download maven configuration: Xml Code collection code <dependency> <groupId> com. google. zxing </groupId> <artifactId> core </artifactId> <version> 3.2.1 </version> </dependency> Java code collection code package com. util. cccm; import java. awt. basicStroke; import java. awt. graphics; import java. awt. graphics2D; import java. awt. image; import java. awt. shape; import java. awt. geom. roundRectangle2D; import java. awt. image. bufferedImage; import java. io. file; Import java. io. outputStream; import java. util. hashtable; import java. util. random; import javax. imageio. imageIO; import com. google. zxing. barcodeFormat; import com. google. zxing. binaryBitmap; import com. google. zxing. decodeHintType; import com. google. zxing. encodeHintType; import com. google. zxing. multiFormatReader; import com. google. zxing. multiFormatWriter; import com. google. zxing. result; import com. Google. zxing. common. bitMatrix; import com. google. zxing. common. hybridBinarizer; import com. google. zxing. qrcode. decoder. errorCorrectionLevel;/*** QR code tool class **/public class QRCodeUtil {private static final String CHARSET = "UTF-8"; private static final String FORMAT_NAME = "JPG "; // QR code size: private static final int QRCODE_SIZE = 300; // logo width: private static final int WIDTH = 60; // LOGO height: private st Atic final int HEIGHT = 60; private static BufferedImage createImage (String content, String imgPath, boolean needCompress) throws Exception {Hashtable <EncodeHintType, Object> hints = new Hashtable <EncodeHintType, object> (); hints. put (EncodeHintType. ERROR_CORRECTION, ErrorCorrectionLevel. h); hints. put (EncodeHintType. CHARACTER_SET, CHARSET); hints. put (EncodeHintType. MARGIN, 1); BitMatrix bitMatrix = New MultiFormatWriter (). encode (content, BarcodeFormat. QR_CODE, QRCODE_SIZE, QRCODE_SIZE, hints); int width = bitMatrix. getWidth (); int height = bitMatrix. getHeight (); BufferedImage image = new BufferedImage (width, height, BufferedImage. TYPE_INT_RGB); for (int x = 0; x <width; x ++) {for (int y = 0; y