BeRo
BeRo

Reputation: 137

I cannot detect shipping label barcodes with ZXing.Net.Maui

in my .NET Maui 8.0 mobile app, I need to be able to scan barcodes. I am using the NuGet package ZXing.Net.Maui. I set everything up according to their Git page.

My setup

I added the NuGet packages ZXing.Net.MAUI and ZXing.Net.MAUI.Controls, added .UseBarcodeReader() to my builder in CreateMauiApp, and use the control in XAML like this:

<Frame Grid.Row="3"
       Padding="0">
    <zxing:CameraBarcodeReaderView x:Name="cameraBarcodeReaderView"
                                   BarcodesDetected="BarcodesDetected" />
</Frame>

The XAML reference to zxing is defined as

xmlns:zxing="clr-namespace:ZXing.Net.Maui.Controls;assembly=ZXing.Net.MAUI.Controls"

In the page's code-behind class I use the following code to set the options in the constructor, right after calling InitializeComponent().

cameraBarcodeReaderView.Options = new BarcodeReaderOptions
{
    Formats = BarcodeFormats.All,
    AutoRotate = true,
    Multiple = true,
    TryHarder = true,
    TryInverted = true
};

The following function from the same class handles detected barcodes.

private void BarcodesDetected(object sender, BarcodeDetectionEventArgs e)
{
    _logService?.LogInfo($"{this}.BarcodesDetected > {nameof(sender)} = {sender}, {nameof(e)} = [{e}]");

    foreach (var barcode in e.Results)
    {
        _logService?.LogInfo($"{this}.BarcodesDetected > {nameof(sender)} = {sender}, {nameof(e)} = [{e}] > Barcode: {barcode.Format} -> {barcode.Value}");

        _viewModel.ProcessScan(new ScanResult(ScanSource.BarcodeScan, barcode.Value, barcode.Raw));
    }
}

The View Model then processes the scans.

My problem

We need to support different types of barcodes for different modules of the app. For one module which uses one-dimensional barcodes like Code 128, it works great! No complaints, everything works!

However, I cannot scan any FedEx shipping label barcodes. These are two-dimensional barcodes and according to a website they are PDF417 barcodes. I do not get any event for them. If I move the phone further down where the one-dimensional barcode is on the shipping label, it is properly detected. However, the two-dimensional one - which is important for us - is not detected.

What I tried

I tried setting the options for the barcode scanner View in different locations like the constructor of the page or into the Loaded event, but it never triggers for the 2-D barcode. I also tried changing the Formats setting to BarcodeFormats.TwoDimensional or BarcodeFormat.Pdf417, but I have no luck.

I assume it is just a setting error, but what do I miss?

Upvotes: 0

Views: 94

Answers (0)

Related Questions