繁体   English   中英

如何使用zxing库文件生成65 * 65 Qr代码?

[英]How to generate 65 * 65 Qr code using zxing library file?

我可以使用zxing库文件(版本1.7.0)生成90 * 90 Qr Code。 但是当我给图像的尺寸小于90时,Qrcode数据填充区域变得太小,请看以下示例 在此处输入图片说明

尺寸保持为90 * 90时,

在此处输入图片说明

同时保持尺寸为89 * 89 ..

我想生成65 * 65 Qr代码,请帮助我。

String myCodeText = "Success";
String filePath = "D:/CrunchifyQR.png";
int size = 90;  
String fileType = "png"

Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<EncodeHintType, ErrorCorrectionLevel>();
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);

QRCodeWriter qrCodeWriter = new QRCodeWriter();
ByteMatrix byteMatrix = qrCodeWriter.encode(myCodeText,BarcodeFormat.QR_CODE, size, size, hintMap);
int CrunchifyWidth = byteMatrix.getWidth() ;
BufferedImage image = new BufferedImage(CrunchifyWidth, CrunchifyWidth, BufferedImage.TYPE_INT_RGB);
image.createGraphics();

Graphics2D graphics = (Graphics2D) image.getGraphics();
graphics.setColor(Color.BLACK);
graphics.fillRect(0, 0, CrunchifyWidth, CrunchifyWidth);
graphics.setColor(Color.GRAY);

byte[][] byteArr = byteMatrix.getArray();

for (int i = 0; i < CrunchifyWidth; i++) {
    for (int j = 0; j < CrunchifyWidth; j++) {
        int grayValue = byteArr[i][j] & 0xff; 
        if (grayValue != 0) {
            graphics.fillRect(i, j, 1, 1);
        }
    }
}

ImageIO.write(image, fileType, myFile);

尝试将MARGIN属性设置为1(默认情况下等于4),如下所示:

Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<EncodeHintType, ErrorCorrectionLevel>();
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);

hintMap.put(EncodeHintType.MARGIN, 1);

希望对您有所帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM