In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what is the method of generating QR code by zxing". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the method of generating QR code by zxing"?
POM
Com.google.zxing core 3.1.0 com.google.zxing javase 3.1.0
Utils
Package com.egl.utils;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.client.j2se.BufferedImageLuminanceSource;import com.google.zxing.common.BitMatrix;import com.google.zxing.common.HybridBinarizer;import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;/** * lee * / public class QRCodeUtil {private static final String CHARSET = "utf-8"; private static final String FORMAT = "JPG" / / QR code size private static final int QRCODE_SIZE = 300; / / LOGO width private static final int LOGO_WIDTH = 60; / / LOGO height private static final int LOGO_HEIGHT = 60; private static BufferedImage createImage (String content, String logoPath, boolean needCompress) throws Exception {Hashtable hints = new Hashtable (); 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 < height; y++) { image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF); } } if (logoPath == null || "".equals(logoPath)) { return image; } // 插入图片 QRCodeUtil.insertImage(image, logoPath, needCompress); return image; } /** * 插入LOGO * * @param source * 二维码图片 * @param logoPath * LOGO图片地址 * @param needCompress * 是否压缩 * @throws Exception */ private static void insertImage(BufferedImage source, String logoPath, boolean needCompress) throws Exception { File file = new File(logoPath); if (!file.exists()) { throw new Exception("logo file not found."); } Image src = ImageIO.read(new File(logoPath)); int width = src.getWidth(null); int height = src.getHeight(null); if (needCompress) { // 压缩LOGO if (width >Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 272
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.