I use zxing library to generate QRcode. When I generate QR it work fine but it have a white space on left and right side of QR. How to remove this white space (to make a bitmap width=height)
Here is my code to generate QR
private static final int QR_SIZE = 480;
public static Bitmap generateQR(String content){
Bitmap returnBitmap= null;
try {
Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<EncodeHintType, ErrorCorrectionLevel>();
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
QRCodeWriter qrCodeWriter = new QRCodeWriter();
BitMatrix matrix = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, QR_SIZE, QR_SIZE, hintMap);
//int width = matrix.getWidth();
int width = matrix.getHeight();
int height = matrix.getHeight();
int[] pixels = new int[width*height];
for(int y=0; y<height; y++) {
for(int x=0; x<width; x++) {
int grey = matrix.get(x, y) ? 0x00 : 0xff;
pixels[y*width+x] = 0xff000000 | (0x00010101*grey);
}
}
returnBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
returnBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
//returnBitmap.set
} catch (Exception e) {
Log.d(LOGTAG, e.toString());
}
return returnBitmap;
}
Too late for the answer, but can be used in future.
White space can be removed by using below code sample
Map<EncodeHintType, Object> hintMap = new HashMap<EncodeHintType, Object>();
hintMap.put(EncodeHintType.MARGIN, new Integer(1));
BitMatrix matrix = new MultiFormatWriter().encode(
new String(qrCodeData.getBytes(charset), charset),
BarcodeFormat.QR_CODE, qrCodewidth, qrCodeheight, hintMap);
Don't remove the white space, it is required by the spec.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With