-8

Android 二维码生成数字

com.google.zxing.Writer writer = new UPCAWriter();
String finaldata = Uri.encode(data, characterEncoding);
BitMatrix bm = writer.encode(finaldata, mBarcodeFormat, bitmapWidth,bitmapHeight);
ImageBitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight,Config.ARGB_8888);

for (int i = 0; i < bitmapWidth; i++) {
for (int j = 0; j < bitmapHeight; j++) {
    ImageBitmap.setPixel(i, j, bm.get(i, j) ? Color.BLACK: Color.WHITE);
}

}

4

1 回答 1

2

试试这个

public void generateQRCode_general(String data, ImageView img)throws WriterException {
    com.google.zxing.Writer writer = new QRCodeWriter();
    String finaldata = Uri.encode(data, characterEncoding);

    BitMatrix bm = writer.encode(finaldata, BarcodeFormat.QR_CODE,bitmapWidth, bitmapHeight);
    ImageBitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight,Config.ARGB_8888);

    for (int i = 0; i < bitmapWidth; i++) {
        for (int j = 0; j < bitmapHeight; j++) {
            ImageBitmap.setPixel(i, j, bm.get(i, j) ? Color.BLACK: Color.WHITE);
        }
    }

    if (ImageBitmap != null) {
        img.setImageBitmap(ImageBitmap);
    } else {
        Toast.makeText(activity,"Uable to setImageBitmap \n ImageBitmap is NULL",Toast.LENGTH_LONG).show();
    }
}

对于数字使用这个

com.google.zxing.Writer writer = new UPCAWriter();
String finaldata = Uri.encode(data, characterEncoding);
    BitMatrix bm = writer.encode(finaldata, mBarcodeFormat, bitmapWidth,bitmapHeight);
    ImageBitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight,Config.ARGB_8888);

    for (int i = 0; i < bitmapWidth; i++) {
        for (int j = 0; j < bitmapHeight; j++) {
            ImageBitmap.setPixel(i, j, bm.get(i, j) ? Color.BLACK: Color.WHITE);
        }
    }

UPCA 有 12 个号码的限制

于 2012-10-29T11:37:00.957 回答