【问题标题】:How to generate 65 * 65 Qr code using zxing library file?如何使用 zxing 库文件生成 65 * 65 的二维码?
【发布时间】:2015-04-06 10:24:41
【问题描述】:

我可以使用 zxing 库文件(版本 1.7.0)生成 90 * 90 的二维码。但是当我给图像的尺寸小于 90 时,Qrcode 数据填充区域变得太小,请看以下示例

同时保持尺寸为 90 * 90,

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

我想生成 65 * 65 的二维码,请帮帮我。

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);

【问题讨论】:

  • 您能否发布一些您用来执行此操作的代码,以便我们为您提供帮助?
  • Hi Wai Ha Lee,我在上面添加了我的代码
  • 可能是像素比例的原因。没有像 1/2 像素这样的东西。
  • QCodeWriter 类可能会补偿静区填充。在图像边缘和二维码之间至少应该有four (4) modules of margin

标签: java zxing qr-code


【解决方案1】:

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

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

hintMap.put(EncodeHintType.MARGIN, 1);

希望对你有帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-14
    • 1970-01-01
    • 2014-04-17
    • 1970-01-01
    • 2020-12-19
    相关资源
    最近更新 更多