ZXing .Net - Unable to decode/read any barcodes in images

2k Views Asked by At

I am trying to use ZXing .Net to decode barcodes in images taken from a camera but it is not working for any image I try.

Here's the code I'm currently using:

protected void ReadBarcodeZXing(string imagePath)
{
    BarcodeReader reader = new BarcodeReader()
    {
        Options =
            {
                TryHarder = true,
                ReturnCodabarStartEnd = false,
                PureBarcode = false
            }
    };

    Bitmap barcodeBitmap = (Bitmap)Bitmap.FromFile(imagePath);

    var result = reader.Decode(barcodeBitmap);

    if (result != null)
        lblResult.Text = result.BarcodeFormat.ToString() + "<br />" + result.Text;
    else
        lblResult.Text = "No barcodes found in image";

    barcodeBitmap.Dispose();
}

I've tried with AutoRotate and TryInverted set to true and I've tried using PossibleFormats.

Here are some barcode images I've tried decoding:

1: https://i.stack.imgur.com/Kg8z7.jpg

2: https://i.stack.imgur.com/CZaon.jpg (Close-up of #1)

3: https://i.stack.imgur.com/3sxCs.jpg

4: https://i.stack.imgur.com/WYlO8.jpg

5: https://i.stack.imgur.com/fWKbU.jpg (Close-up of #4)

6: https://i.stack.imgur.com/lfbk1.jpg

7: https://i.stack.imgur.com/Sezh5.jpg

#6 & #7 are sample images provided on the GitHub project. There were more samples that didn't work but many of them did work.

Anyone able to help me get it working properly? Or help me understand why it's not working for my own images?

0

There are 0 best solutions below