java - QRcode 和 BarQRCode itextpdf
问题描述
我需要按照一些技术规范创建一个二维码,例如:二维码符号版本()、模块()、模块宽度()、ECC级别()和字符集()。我必须使用itextpdf库,而我获得的必须成为awt.Image。
我尝试同时使用QRCode和BarcodeQRCode。使用 QRCode 我设置符号版本、模块、模块宽度和 ECC 级别。然后使用 BarcodeQRCode 设置字符集,我可以获得 awt.Image。
问题是我无法将 QRCode 传递给 BarcodeQRCode。你知道如何解决这个问题并使用这个库获得完整的二维码/图像吗?
这是我的代码:
StringBuffer sb = new StringBuffer ();
sb.append ( QRCODE_IDENTIFICATIVO );
// other lines with the content of qrcode
QRCode qrCode = new QRCode ();
qrCode.setVersion ( versione );
qrCode.at ( modulesWidth, modulesHeight );
qrCode.setMatrixWidth ( modulesWidth );
qrCode.setECLevel ( ErrorCorrectionLevel.M );
Map<EncodeHintType, Object> qrParam = new HashMap<EncodeHintType, Object> ();
qrParam.put ( EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M );
qrParam.put ( EncodeHintType.CHARACTER_SET, "UTF-8" );
BarcodeQRCode qrcode = new BarcodeQRCode ( sb.toString (), (int) mmToPt ( 30f ), (int) mmToPt ( 30f ), qrParam );
return qrcode.createAwtImage ( Color.BLACK, Color.WHITE );
谢谢
解决方案
我明白如何解决这个问题。版本 4 是具有 33 个模块(或模块宽度 = 33)的版本。因此,当 barQRcode 初始化时,第二个和第三个参数设置模块的数量,因此,版本和模块宽度也设置。而 EncodeHintType 则包含有关字符和纠错的信息。这样,所有信息都可以在不使用二维码的情况下使用。这是:
StringBuffer sb = new StringBuffer ();
sb.append ( QRCODE_IDENTIFICATIVO );
// other lines with the content of qrcode
Map<EncodeHintType, Object> qrParam = new HashMap<EncodeHintType, Object> ();
qrParam.put ( EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M );
qrParam.put ( EncodeHintType.CHARACTER_SET, "UTF-8" );
BarcodeQRCode qrcode = new BarcodeQRCode ( sb.toString (), 33, 33, qrParam );
return qrcode.createAwtImage ( Color.BLACK, Color.WHITE );
推荐阅读
- javascript - dataTables AdminLTE3 模板中的文本对齐
- python - SQLAlchemy 删除多对多行
- php - PHP openssl MCRYPT_RIJNDAEL_128 等效
- python - LSTM 的输入维度
- r - 至少一个类级别不是有效的 R 变量名
- android - 关闭屏幕时,我在华为设备上遇到 IDLE 模式问题
- javascript - 如何覆盖 d3.js 的 linkHorizontal() 函数
- c# - 如果您有多个应用程序,将用户存储在一个表中,并使用区分应用程序的列是一种好的设计实践吗?
- angular - 在角度的 mat-toggle 上使用 ::ng-deep 时 attr 绑定不起作用
- mule - Mule 4 中的 HTTP 请求