我使用zxing库来生成二维码。当我生成 QR 时它工作正常,但它在 QR 的左右两侧有一个空白区域。如何删除此空白(使位图宽度=高度)
这是我生成 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;
}