Vaz*_*ias 4 android qr-code zxing
我使用zxing库生成二维码。当我生成 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;
}
Run Code Online (Sandbox Code Playgroud)
答案为时已晚,但可以在将来使用。
可以使用以下代码示例删除空格
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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12993 次 |
| 最近记录: |