使用zxing生成二维码的方法步骤
zxing
ZXing ("Zebra Crossing") barcode scanning library for Java, Android
项目地址:https://gitcode.com/gh_mirrors/zx/zxing

·
1、二维码中的信息
2、通过zxing生成二维码 (保存到本地图片, 支持以data url 的形式体现)
2.1、创建QRCodeWriter对象
2.2、设置生成的图片基本配置
配置参数
1.二维码信息
2.图片类型
3.图片宽度
4.图片长度
3、保存到本地
3.1、保存的路径
3.2、使用MatrixToImageWriter.writeToPath()保存
需要的jar包 :
core-3.3.3.jar
代码如下:
package cn.cfg;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
/**
* @Author: 陈福国
* 生成二维码
*/
public class QRCodeTest {
public static void main(String[] args) throws WriterException, IOException {
//1.二维码中的信息
String value ="https://blog.csdn.net/qq_45112637";
//2.通过zxing生成二维码 (保存到本地图片, 支持以data url 的形式体现)
//创建QRCodeWriter对象
QRCodeWriter writer = new QRCodeWriter();
//生成的图片基本配置
/*
参数
1.二维码信息
2.图片类型
3.图片宽度
4.图片长度
*/
BitMatrix bt = writer.encode(value, BarcodeFormat.QR_CODE, 200, 200);
//保存到本地
Path path = new File("C:\\Users\\Administrator\\Desktop\\test.png").toPath();
MatrixToImageWriter.writeToPath(bt,"png",path);
}
}




ZXing ("Zebra Crossing") barcode scanning library for Java, Android
最近提交(Master分支:19 天前 )
0a14de90
1 个月前
f2813890
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v4...v5)
---
updated-dependencies:
- dependency-name: actions/checkout
dependency-version: '5'
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 1 个月前
更多推荐
所有评论(0)