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