gven21
gven21

Reputation: 43

How to decode EAN128 barcode with zxing barcode scanning library

I am trying to read an EAN128 barcode using zxing barcode scanning library. And I am using it in the Xamarin shared project like this…

private async void OnButtonForBarcodeReadPressed(object sender, EventArgs e)
{
    ZXingScannerPage scannerPage = new ZXingScannerPage();
    scannerPage.OnScanResult += (result) =>
    {
        scannerPage.IsScanning = false;
        var rawBytes = result.RawBytes;
        var barcodeType = result.BarcodeFormat.ToString();
        var barcodeText = result.Text;
    };
}

The problem is that the Text property of the result does not contain the special character.

I noticed that the property RawBytes of the result (which is a byte array) has a byte 102 in correct place for every special character but I can't seem to understand how the rest of the bytes have been calculated.

Here is an example. I generate this EAN128 barcode (21)500600(11)201201. I did it with an online barcode generator so I am sure that there is a special character in the right place! When I scan it with zxing the Text property of the result is "2150060011201201" and the length is exactly 16 chars so there is no special character included. And this is an image of the byte array in the RawBytes property. As you can see before every application identifier there is a byte 102. But the rest seem a bit of. And when you add a letter in the barcode then it is more confusing.

Is there a way to get the correct barcode text with the special character from the property RawBytes or a way to configure the zxing so the Text property contains the special character?

Upvotes: 2

Views: 1178

Answers (1)

Lucas Zhang
Lucas Zhang

Reputation: 18861

You need to set the BarcodeFormat of the ScanningOptions .

var options = new ZXing.Mobile.MobileBarcodeScanningOptions
{
    PossibleFormats = new List<ZXing.BarcodeFormat>() {
          ZXing.BarcodeFormat.CODE_128
    },

    ryHarder = true,
    AssumeGS1 = true,
    AutoRotate = true,

};

Upvotes: 2

Related Questions