0

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?

Community
  • 1
  • 1
user3636407
  • 103
  • 1
  • 10
  • Code all looks right. Tried it on my machine and couldn't get your images to be recognized, then ran them through several online barcode scanners and none of them were recognized. My only other thought could be the image quality and/or light reflection. – DCCoder Sep 17 '18 at 02:23
  • @DCCoder They work using Dynamosoft Barcode reader and QuaggaJS at least – user3636407 Sep 17 '18 at 02:28
  • May just be an issue with ZXing then. Leave a response under the issues section in their official Github. – DCCoder Sep 17 '18 at 02:46

0 Answers0