java实现二维码图片生成和编解码
在wutool
中,封装了二维码工具类,基于google
的zxing
库,实现二维码图片生成、编码和解码。
关于wutool
wutool
是一个java代码片段收集库,针对特定场景提供轻量解决方案,只要按需选择代码片段拷贝使用即可。项目git地址https://github.com/handsomestWei/wutool
,欢迎star
二维码工具类使用
代码片段地址https://github.com/handsomestWei/wutool/tree/main/src/main/java/com/wjy/wutool/util/QrCodeUtil.java
maven依赖
<dependency><groupId>com.google.zxing</groupId><artifactId>javase</artifactId><version>3.3.0</version>
</dependency>
编码:生成二维码图片文件
/*** @param content 二维码内容* @param path 二维码图片输出路径* @param width 二维码图片宽度* @param height 二维码图片高度*/
public static void createQRCode(String content, String path, int width, int height);
解码:解析二维码图片内容
/*** @param filePath 二维码图片路径* @return 二维码内容*/
public static String decodeQRCode(String filePath);