Java 实现定制二维码,附源码

本文由用户“beichen1986”分享发布 更新时间:2023-05-08 20:09:00 举报文档

以下为《Java 实现定制二维码,附源码》的无排版文字预览,完整格式请下载

下载前请仔细阅读文字预览以及下方图片预览。图片预览是什么样的,下载的文档就是什么样的。

Java 实现定制二维码,附源码

步骤 1

第一步首先创建一个普通的 Maven 项目,然后要实现二维码功能,我们肯定要使用别人提供好的 Jar 包,这里我用的是 google 提供的 jar,pom.xml 文件配置如下:

4.0.0 org.javaboy QRCode 1.0-SNAPSHOT com.google.zxing core 3.3.0

步骤 2

然后使用 google 提供的工具类,在项目根目录下创建一个 util 包,将所需要的工具类放进去。/

工具类1 (BufferedImageLuminanceSource)

不废话,直接上代码

/** * @author bai * @date 2020/7/1 9:27 */public class BufferedImageLuminanceSource extends LuminanceSource { private final BufferedImage image; private final int left; private final int top; public BufferedImageLuminanceSource(BufferedImage image) { this(image, 0, 0, image.getWidth(), image.getHeight()); } public BufferedImageLuminanceSource(BufferedImage image, int left, int top, int width, int height) { super(width, height); int sourceWidth = image.getWidth(); int sourceHeight = image.getHeight(); if (left + width > sourceWidth || top + height > sourceHeight) { throw new IllegalArgumentException("Crop rectangle does not fit within image data."); } for (int y = top; y < top + height; y++) { for (int 内容过长,仅展示头部和尾部部分文字预览,全文请查看图片预览。 strator\\Pictures\\img\\dog.jpg"; // 生成的二维码的路径及名称 String destPath = "C:\\Users\\bai\\Pictures\\img\\code" + System.currentTimeMillis() + ".jpg"; //生成二维码 QRCodeUtil.encode(text, null, destPath, true); // 解析二维码 String str = QRCodeUtil.decode(destPath); // 打印出解析出的内容 System.out.println(str); }}

效果截图

/

[文章尾部最后300字内容到此结束,中间部分内容请查看底下的图片预览]

以上为《Java 实现定制二维码,附源码》的无排版文字预览,完整格式请下载

下载前请仔细阅读上面文字预览以及下方图片预览。图片预览是什么样的,下载的文档就是什么样的。

图片预览