Jibin Balachandran
Jibin Balachandran

Reputation: 3441

Getting NULL value for barcode decoding

I have added the Zxing.Net from NuGet Package Manager in VS 2015. I tried the following code for decoding a CODE_128 barcode. But its giving null as result. The same image is getting decoded successfully in almost all the online barcode reading websites including Zxing Online Decoder.

using System;
using System.Drawing;
using ZXing.QrCode;
using ZXing.QrCode.Internal;

public string barcode_scan()
{
    string qr = @"C:\Users\Admin\Desktop\barcode.jpg";
    ZXing.BarcodeReader reader = new ZXing.BarcodeReader();
    var result = reader.Decode((Bitmap)Bitmap.FromFile(qr));
    return result;
}

I'm not able to make out where I'm going wrong.

Edit: Image Attached Image with barcode

Upvotes: 2

Views: 3091

Answers (2)

C.Evenhuis
C.Evenhuis

Reputation: 26446

If you crop out a piece of the image, the barcode is decoded correctly. Apparently zxing cannot determine that the "MDS" barcode is the barcode you're trying to scan.

Simply removing the EAN13 from the image is not enough, but if you have an image with just the vertical "elephant bar" it does find the barcode:

enter image description here

In other words, you'll need to "aim" the scanner :)

Upvotes: 1

Patrick
Patrick

Reputation: 5866

Have you tried with:

ZXing.BarcodeReader reader = new ZXing.BarcodeReader()
{
    AutoRotate = true,
    TryInverted = true,
    Options = new DecodingOptions
    {
        TryHarder = true,
        PureBarcode = true,
        PossibleFormats = new List<BarcodeFormat> { BarcodeFormat.CODE_128 }
    }
};

This won't be optimized for speed, but if it works, you can remove some of the brute-force options.

Upvotes: 2

Related Questions