Reputation: 1579
I'm trying to decode barcodes on magazines and comic books. These guys sometimes have an "extension" of 2 or 5 digits stored in a slightly separated code; it is used to encode things like the issue number. It's described here.
In my application, I've written this proof of concept method:
[HttpPost]
public string Post([FromForm] IFormFile file)
{
string barcode = string.Empty;
using (var stream = file.OpenReadStream())
{
try
{
stream.Seek(0, SeekOrigin.Begin);
using var coreCompatImage = (Bitmap)Bitmap.FromStream(stream);
var coreCompatReader = new ZXing.Windows.Compatibility.BarcodeReader();
coreCompatReader.Options.PossibleFormats = new List<BarcodeFormat> { BarcodeFormat.UPC_A };
var coreCompatResult = coreCompatReader.Decode(coreCompatImage);
var multipleCodes = coreCompatReader.DecodeMultiple(coreCompatImage);
barcode = coreCompatResult?.Text ?? string.Empty;
}
catch (Exception exc)
{
return "Error processing the image: ";
}
}
return barcode;
}
I was hoping multipleCodes
would pick up both barcodes, but I only get the first 12 digits.
How do I convince ZXing to return "75966066620843200131" instead of "759660666208432"?
Upvotes: 1
Views: 104