要解决的问题:
- 1、在做二维码分享时;要将二维码嵌入到特定位置;
不都逼逼,直接上代码:
导入maven架包:
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.1.0</version>
</dependency>
Util类:
package com.thok.project.tool.QRCode;
import com.google.zxing.*;
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;
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;
import java.awt.*;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Hashtable;
import java.util.Random;
/**
* 生成二维码工具类
*/
public class CreateQr{
private static final String CHARSET="utf-8";
private static final String FORMAT_NAME="JPG";
//二维码尺寸
private static final int QRCODE_SIZE=280;
//LOGO宽度
private static final int WIDTH=60;
//LOGO高度