micjahn / ZXing.Net

.Net port of the original java-based barcode reader and generator library zxing
Apache License 2.0
2.73k stars 665 forks source link

BarcodeReader returns Pharmacode as result when image contains no readable code #515

Closed BlyZeDev closed 1 year ago

BlyZeDev commented 1 year ago

When I try to decode a DataMatrix the result is always a Pharmacode with some random numbers. In this case 511.

Sample image: Content of the code: "Cool Test Code."

My code:

private static readonly BarcodeFormat[] _formats = new BarcodeFormat[]
    {
        BarcodeFormat.AZTEC,
        BarcodeFormat.CODABAR,
        BarcodeFormat.CODE_128,
        BarcodeFormat.CODE_39,
        BarcodeFormat.CODE_93,
        BarcodeFormat.DATA_MATRIX,
        BarcodeFormat.EAN_13,
        BarcodeFormat.EAN_8,
        BarcodeFormat.IMB,
        BarcodeFormat.ITF,
        BarcodeFormat.MAXICODE,
        BarcodeFormat.MSI,
        BarcodeFormat.PDF_417,
        BarcodeFormat.PHARMA_CODE,
        BarcodeFormat.PLESSEY,
        BarcodeFormat.QR_CODE,
        BarcodeFormat.RSS_14,
        BarcodeFormat.RSS_EXPANDED,
        BarcodeFormat.UPC_A,
        BarcodeFormat.UPC_E,
        BarcodeFormat.UPC_EAN_EXTENSION
    };

public DecodeResult Decode(Bitmap bitmap, bool bw = true)
    {
        _logger.LogDebug("Decoding Bitmap");

        var result = GetReader(bw).Decode(bitmap);

        _logger.LogDebug("Decoded Bitmap with result: {result}", result);

        return DecodeResult.FromResult(result);
    }

private static BarcodeReader GetReader(bool bw)
    {
        return new BarcodeReader()
        {
            AutoRotate = true,
            Options = new DecodingOptions
            {
                PureBarcode = bw,
                TryHarder = true,
                TryInverted = true,
                UseCode39RelaxedExtendedMode = true,
                PossibleFormats = _formats
            }
        };
    }

Thanks in advance! :)

BlyZeDev commented 1 year ago

When I remove PharmaCode from the BarcodeFormat[] then I just returns null like it should when it doesn't find anything. But then it can't read Pharmacodes.

BlyZeDev commented 1 year ago

I deaktivated IMB, Pharmacode and MSI and it seems to work now.