Java QR code tool class, with a LOGO in the middle, very powerful, java tool class logo

Source: Internet
Author: User

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 

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.