-8

数字の Android QR コード生成

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 に答える