2012-07-30 187 views
1

用下面的代碼QR碼出現在黑莓屏幕空白,我不知道我錯過了什麼。它顯示了一個正確居中的正方形,但正方形本身是白色的,裏面沒有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); 
} 

}

回答

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模擬器(運行你的原始代碼生成你所描述的空白圖像)。