使用新的createbitmap方法时如何设置QR码的纠错级别

Gop*_*ian 5 blackberry qr-code zxing

这个问题参考API文档链接,http://www.blackberry.com/developers/docs/7.0.0api/net/rim/device/api/barcodelib/BarcodeBitmap.html

他们指定旧方法

public static Bitmap createBitmap(ByteMatrix byteMatrix,
                                  int maxBitmapSizeInPixels) 
Run Code Online (Sandbox Code Playgroud)

已弃用。

但通过使用新方法,

public static Bitmap createBitmap(ByteMatrix byteMatrix)
Run Code Online (Sandbox Code Playgroud)

他们没有指定一种方法来指定 Multiformatwriter 中 QR 码的纠错级别。我也没有找到办法,查看了各种成员函数。有人试过这个吗?

感谢您的帮助。

Eug*_*ene 6

这是我的代码,我已经用我的手机检查过,纠错级别根据我的手机设置正确。

        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;
Run Code Online (Sandbox Code Playgroud)


Eug*_*nov 1

刚刚查看了文档。

它说要createBitmap(ByteMatrix byteMatrix)与 结合使用MultiFormatWriter。它具有encode(String contents, BarcodeFormat format, int width, int height, Hashtable hints)可以指定宽度、高度和错误级别的方法。

EncodeHintType.ERROR_CORRECTION要指定错误级别,请将值放入提示哈希表键中new Integer(level)

不幸的是,我没有找到这些值的任何常量,如此处所述。但也许你可以在砍伐资源中找到它。