This project has moved and is read-only. For the latest updates, please go here.

Problem Encoding / Decoding Barcode

Oct 1, 2012 at 11:26 AM


I do have the problem that the barcode decoding does not work properly.

I am using the following code to decode:

EncodingOptions options;
options = new ZXing.QrCode.QrCodeEncodingOptions
    Height = 130,
    Width = 130

var writer = new BarcodeWriter
     Format = BarcodeFormat.QR_CODE,
     Options = options
return writer.Write(code);

No I print that code on a dymo label printer or inkjet printer and glue it on a document.

If I scan that document now, with 200/300 dpi and grayscale the encoding does not work properly.

It is working in 50% of all cases.

I decode in the following way:

Bitmap Picture = null;

BarcodeReader reader = new BarcodeReader();
Result[] results = reader.DecodeMultiple(Picture);

// do something with the result
if (results != null)
      foreach (ZXing.Result singleBarcode in results)
             //finding a valid Barcode
             if (singleBarcode.Text.StartsWith(strIDStart))
             return singleBarcode.Text.Remove(0, strIDStart.Length);

What could be the reason for that problem?

Thanks for your help.

Regards Flyerr

Oct 1, 2012 at 6:13 PM

Can you send me a sample of a scanned document which doesn't work?

The algorithm mainly looks for barcodes in the middle of the picture. You can tweek it if you set reader.TryHarder=true.
Another way to get better results would be if you can crop the picture so that the reader looks only in that part of the document where the
barcode should be. I discussed a similar issue here:

If you only need one barcode result you should better use Decode(Picture) instead of DecodeMultiple.

I think with TryHarder=true and Decode() you should get nearly a success rate of 100%.
But I really want to test it out with a sample picture.

Oct 1, 2012 at 6:43 PM
Edited Oct 1, 2012 at 6:47 PM

Hi micjahn,

thanks for your fast answer.

One example file is

If you like, I could send you a few more files. Just tell me how I could do that in this forum.

I need the DecodeMultiple function, because I do not know how many barcodes will be on the paper. I will later figure out my barcode.

Additionally I do not know where the barcode is sticked on the paper so the solution could be TryHarder? That means search on the complete page?

Regards Flyerr

Oct 1, 2012 at 7:28 PM

I could scan your picture with a reduced size. I resized the image by 50 percent. The result is 'CKS18/257'.
After that I tried it again with a size of 25 percent. The result was even better. Perhaps you should not print the codes that big.
For QR Codes you don't need TryHarder=true. For 1D barcodes like EAN the algorithm tries more scanlines of the picture.

You should try to add a resize filter of 50 percent before decoding the picture. Or scanning with half of the resolution if possible.
I think because of the big barcode size and the high resolution there is to much interference within the black regions of the barcode.

Oct 3, 2012 at 9:06 AM
Edited Jan 3, 2014 at 6:33 AM
Hi micjahn, thats it. Thanks for your help. I solved it with the following code: Bitmap smaller = resizeImage(Picture, new Size(Picture.Width / 3, Picture.Height / 3)); I will donate a few Euros. This projects helps me a lot. Regards Flyerr