2
我可以使用zxing库文件(版本1.7.0)生成90 * 90的Qr代码。但是,当我给不到90大小的图像,QR码数据填充面积过小,看下面的例子 如何使用zxing库文件生成65 * 65 Qr代码?
在保持尺寸为90 * 90,
在保持尺寸as 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);
你能发布一些你用来做这个的代码,所以我们可以帮助你吗? – 2015-04-06 10:41:18
Hi Wai Ha Lee,我在 – PURE 2015-04-06 11:14:18
之上加了我的代码也许是因为像素比例。没有像1/2像素那样的东西。 – 2015-04-06 12:04:05