Search code examples
c#asp.net-mvcbarcodezxingzxing.net

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


Solution

  • 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 :)