Maven导包
<dependency>
<groupId>com.github.liuyueyi.media</groupId>
<artifactId>qrcode-plugin</artifactId>
<version>3.0.0</version>
</dependency>
使用样例
普通二维码
BufferedImage image = QrCodeGenV3.of("https://www.jufb.cn/").build().asImg();
中间带LOGO的二维码
BufferedImage image = QrCodeGenWrapper.of("https://www.jufb.cn/")
//黑色方块变小方块
.setDrawStyle(QrCodeOptions.DrawStyle.MINI_RECT)
.setDrawEnableScale(true)
// 设置二维码颜色
.setDrawPreColor(new Color(203, 156, 73))
// 设置LOGO
.setLogo("/image/icon.png")
// 设置logo大小
.setLogoRate(8)
// 设置LOGO四角样式
.setLogoStyle(QrCodeOptions.LogoStyle.NORMAL)
//设置精度
.setErrorCorrection(ErrorCorrectionLevel.M)
//设置二维码大小
.setW(400)
//true 则探测图形有本身的绘制规则
.setDetectSpecial()
.asBufferedImage();
常用方法
获取图片Base64
public String createJumpQRCode(String url) throws Exception {
BufferedImage image = QrCodeGenV3.of("https://www.jufb.cn/").build().asImg();
String QRCodeBase64Image = null;
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
ImageIO.write(image, “png”, os);
QRCodeBase64Image = Base64.encode(os.toByteArray());
} finally {
os.flush();
os.close();
}
return "data:image/png;base64," + QRCodeBase64Image;
}
2 条评论
看的我热血沸腾啊https://www.ea55.com/
叼茂SEO.bfbikes.com