QR码显示为空白

时间:2012-07-30 16:15:07

标签: java blackberry qr-code zxing

使用以下代码,黑莓屏幕中的QR码显示为空白,我不知道我缺少什么。它显示正确居中的正方形,但正方形本身为白色,内部没有QR码。  任何帮助表示赞赏。感谢。

public QRCodeScreen(String qrCode) {
    this.qrCode = "Test String";
    qrImage = new BitmapField(new Bitmap(QRCODE_WIDTH, QRCODE_WIDTH),FIELD_HCENTER);
    qrImage.setBorder(BorderFactory.createBevelBorder(new XYEdges(2, 2, 2, 2)));

    Hashtable hintMap = new Hashtable();
    hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
    try {
        MultiFormatWriter barcodeWriter = new MultiFormatWriter();
        ByteMatrix byteMatrix = barcodeWriter.encode(this.qrCode, BarcodeFormat.QR_CODE, QRCODE_WIDTH, QRCODE_WIDTH,hintMap);

        Bitmap bitmap = BarcodeBitmap.createBitmap(byteMatrix, 256);

        qrImage.setBitmap(bitmap);
    }
    catch (Exception e) {

    }

    add(qrImage);
}

}

2 个答案:

答案 0 :(得分:1)

查看this sample from the BlackBerry online docs

如果你只是修改它以适合上面的代码,你会得到:

public class QRCodeScreen extends MainScreen {

   private String qrCode;
   private static final int QRCODE_WIDTH = 100;
   private BitmapField qrImage;

   public QRCodeScreen(String qrCode) { 
      this.qrCode = "Test String"; 
      qrImage = new BitmapField(new Bitmap(QRCODE_WIDTH, QRCODE_WIDTH),FIELD_HCENTER); 
      qrImage.setBorder(BorderFactory.createBevelBorder(new XYEdges(2, 2, 2, 2))); 

      try { 
         QRCode code = new QRCode();
         Encoder.encode(qrCode, ErrorCorrectionLevel.L, code);
         ByteMatrix barcode = code.getMatrix();
         Bitmap bitmap = BarcodeBitmap.createBitmap(barcode, QRCODE_WIDTH);
         qrImage.setBitmap(bitmap);         
      } 
      catch (Exception e) { 
         e.printStackTrace();
      } 

      add(qrImage); 
   } 
}

对我来说,在6.0 9800模拟器上运行(运行原始代码会产生如您所述的空白图像)。

答案 1 :(得分:1)

此链接可以帮助您:

Scan Any Type of Barcode Image In Blackberry