How to set error correction level for QR code when using the new createbitmap method
Asked Answered
W

3

5

This question is in reference to the API documentation link, http://www.blackberry.com/developers/docs/7.0.0api/net/rim/device/api/barcodelib/BarcodeBitmap.html

They specify that the old method

public static Bitmap createBitmap(ByteMatrix byteMatrix,
                                  int maxBitmapSizeInPixels) 

is deprecated.

But by using the new method,

public static Bitmap createBitmap(ByteMatrix byteMatrix)

they haven't specified a way to specify the error correction level for the QR code in Multiformatwriter. I haven't been able to find a way either, looking through various member functions. Has anyone tried this?

Thanks for your help.

Wieren answered 18/7, 2012 at 15:54 Comment(0)
S
1

Just looked to the documentation.

It says to use createBitmap(ByteMatrix byteMatrix) in conjunction with MultiFormatWriter. That has method encode(String contents, BarcodeFormat format, int width, int height, Hashtable hints) where you could specify width, height and error level.

To specify error level put to hints hashtable key EncodeHintType.ERROR_CORRECTION with value new Integer(level).

Unfortunately I didn't find any constants for these values as described here. but probably you could find it in axing sources.

Suazo answered 18/7, 2012 at 16:21 Comment(2)
If you are referring to these two lines in the doc, I too looked at them. MultiFormatWriter barcodeWriter = new MultiFormatWriter(); ByteMatrix barcode = barcodeWriter.encode("abcdefg", BarcodeFormat.QR_CODE, 25, 25); But they don't provide a way to mention the Error correction level for the QR code.Wieren
check my answer below for specifics on how to pass in settings for Error correction hints, using ZXing's built-in constantsMachine
N
6

Here is my code, and I have checked with my phone, the error correction level is set correctly according to my phone.

        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;
Northeastward answered 15/8, 2012 at 11:46 Comment(1)
What OS do you have in your phone?Wieren
M
2

When encoding, you can pass in hints

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

Add the error correction setting to the hints (for example to level M)

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

ZXing uses error correction level L by default (the lowest, meaning the QR Code will still be readable even after a max of 7% damage)

Machine answered 3/4, 2015 at 18:1 Comment(0)
S
1

Just looked to the documentation.

It says to use createBitmap(ByteMatrix byteMatrix) in conjunction with MultiFormatWriter. That has method encode(String contents, BarcodeFormat format, int width, int height, Hashtable hints) where you could specify width, height and error level.

To specify error level put to hints hashtable key EncodeHintType.ERROR_CORRECTION with value new Integer(level).

Unfortunately I didn't find any constants for these values as described here. but probably you could find it in axing sources.

Suazo answered 18/7, 2012 at 16:21 Comment(2)
If you are referring to these two lines in the doc, I too looked at them. MultiFormatWriter barcodeWriter = new MultiFormatWriter(); ByteMatrix barcode = barcodeWriter.encode("abcdefg", BarcodeFormat.QR_CODE, 25, 25); But they don't provide a way to mention the Error correction level for the QR code.Wieren
check my answer below for specifics on how to pass in settings for Error correction hints, using ZXing's built-in constantsMachine

© 2022 - 2024 — McMap. All rights reserved.