QRcode 和 BarQRCode itextpdf

QRcode and BarQRCode itextpdf

我需要按照一些技术规范创建二维码,例如:二维码符号版本()、模块()、模块宽度()、ECC 级别() 和字符集()。 我必须使用 itextpdf 库,我得到的东西必须变成 awt.Image.

我尝试同时使用 QRCodeBarcodeQRCode。使用 QRCode,我设置了符号版本、模块、模块宽度和 ECC 级别。然后使用 BarcodeQRCode 我设置了字符集,我可以获得 awt.Image.

问题是我无法将QRCode 传递给BarcodeQRCode。 你知道如何解决这个问题并使用这个库获得完整的 qrcode/image 吗?

这是我的代码:

       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)的版本。因此,当条形码被初始化时,第二个和第三个参数设置模块的数量,因此,版本和模块宽度也是如此。而 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 );