首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用zxing库文件生成65 * 65二维码?

如何使用zxing库文件生成65 * 65二维码?
EN

Stack Overflow用户
提问于 2015-04-06 18:24:42
回答 1查看 1K关注 0票数 2

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

在保持大小为90 * 90的情况下,

同时保持大小为89*89..

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

代码语言:javascript
复制
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);
EN

回答 1

Stack Overflow用户

发布于 2017-05-05 20:16:55

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

代码语言:javascript
复制
Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<EncodeHintType, ErrorCorrectionLevel>();
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);

hintMap.put(EncodeHintType.MARGIN, 1);

我希望它能有所帮助!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29469408

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档