2012-07-18 31 views
2

這個問題是在參考了API文檔的鏈接,http://www.blackberry.com/developers/docs/7.0.0api/net/rim/device/api/barcodelib/BarcodeBitmap.html如何使用新的createbitmap方法

時設置糾錯等級爲QR碼他們指定的舊方法

public static Bitmap createBitmap(ByteMatrix byteMatrix, 
            int maxBitmapSizeInPixels) 

已被棄用。

但是,通過使用新的方法,

public static Bitmap createBitmap(ByteMatrix byteMatrix) 

他們還沒有指定一個方法來指定在Multiformatwriter QR碼的糾錯等級。我也無法找到一種方法,通過各種成員功能進行查看。 有沒有人試過嗎?

感謝您的幫助。

回答

1

只是看文檔。

它說使用createBitmap(ByteMatrix byteMatrix)連同MultiFormatWriter。方法encode(String contents, BarcodeFormat format, int width, int height, Hashtable hints)您可以指定寬度,高度和錯誤級別。

若要指定錯誤級別,請提供值爲new Integer(level)的散列表密鑰EncodeHintType.ERROR_CORRECTION

不幸的是,我沒有找到這些值的任何常量,如here所述。但可能你可以找到它的原始資料。

+0

如果您指的是這些文檔中有兩行,我也看過他們。 'MultiFormatWriter barcodeWriter = new MultiFormatWriter(); ByteMatrix barcode = barcodeWriter.encode(「abcdefg」,BarcodeFormat.QR_CODE,25,25);'但他們沒有提供提供QR碼錯誤校正級別的方法。 – 2012-07-18 16:47:56

+0

查看我的答案,下面是關於如何通過錯誤修正提示的設置,使用ZXing的內置常量的具體細節 – mmcrae 2015-10-26 14:23:39

2

這是我的代碼,我已經檢查過我的手機,錯誤更正級別根據我的手機正確設置。

 Hashtable hints = new Hashtable(); 
     switch (comboBox1.Text) 
     { 
      case "L": 
       hints.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L); 
       break; 
      case "Q": 
       hints.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.Q); 
       break; 
      case "H": 
       hints.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); 
       break; 
      default: 
       hints.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M); 
       break; 
     } 
     MultiFormatWriter mw = new MultiFormatWriter(); 
     ByteMatrix bm = mw.encode(data, BarcodeFormat.QR_CODE, size, size, hints); 
     Bitmap img = bm.ToBitmap(); 
     pictureBox1.Image = img; 
+0

你的手機有哪些操作系統? – 2012-08-16 17:57:47

1

當編碼時,可以在提示通過

Map<EncodeHintType, Object> hints = new Hastable<EncodeHintType, Object>(); 

添加糾錯設置爲提示(例如到等級M)

hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M); 

斑馬線使用錯誤校正電平L默認情況下(最低,這意味着即使在最大7%的傷害後QR碼仍然可讀)