Reputation: 439
I'm trying to generate and scan EAN-13 barcode :
BarcodeReader barcodeReader = new BarcodeReader();
BarcodeWriter barcodeWriter = new BarcodeWriter
{
Format = BarcodeFormat.EAN_13
};
barcodeWriter.Options.Height = 200;
barcodeWriter.Options.Width = 200;
barcodeReader.Options.PossibleFormats = new List<BarcodeFormat>();
barcodeReader.Options.PossibleFormats.Add(BarcodeFormat.EAN_13);
barcodeReader.Options.TryHarder = true;
string content = "123123123123";
Bitmap barcodeBitmap = barcodeWriter.Write(content);
var res = barcodeReader.Decode((Bitmap)barcodeBitmap); //res == null
Console.WriteLine(res.Text);
Why ZXing.net can't scan barcodes generated by itself?
UPD:
I print barcode on A4 paper, scan it and crop by image editor like this :
ZXing can't scan this barcode too
Upvotes: 0
Views: 2354
Reputation: 26100
EAN-13 barcodes require a horizontal quiet zone (margin). BarcodeReader
appears to be failing to detect the barcode because there is not enough blank space to the left and right of the image.
I set the Margin
option before writing the barcode and was able to create a barcode image that could then be read:
barcodeWriter.Options.Margin = 6;
The documentation says this should produce a 6 pixel horizontal margin. However, in practice I'm seeing a much larger margin in the generated image.
Your printed then scanned image appears to be failing to be read because of the vertical white line artefact in the 5th bar from the left. I removed this white line from your image (see below) and BarcodeReader
was then able to successfully read the barcode.
Upvotes: 1