Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZXing.Net.Maui doesn't seem to be able scan more complicated PDF417 barcodes #174

Open
gtvracer opened this issue Mar 15, 2024 · 4 comments

Comments

@gtvracer
Copy link

gtvracer commented Mar 15, 2024

Using ZXing.Net.Maui.Controls v0.4.0 and the basic ZXing page, and configuration, it can detect simple PDF417, but it fails to detect more complex ones, like the one on the back of a California drivers license. It also doesn't keep the torch on either, but flashes once when the page initializes. I've tried the barcode images samples on the internet by searching for "PDF417 images", only the simple ones are read....

The Xamarin version of ZXing is able to read the CA drivers license barcode, fyi..

I'm using Visual Studio v17.9.2, XCode 15.3 and .net8.

Any insight will be appreciated. Thanks!

Page:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:zxing="clr-namespace:ZXing.Net.Maui.Controls;assembly=ZXing.Net.MAUI.Controls"
             x:Class="MyProject.Views.ScanPage"
             Title="ScanPage">   
        <zxing:CameraBarcodeReaderView
			x:Name="barcodeView"
                        IsTorchOn="True"
			BarcodesDetected="BarcodesDetected" />        
</ContentPage>

Code behind:

public partial class ScanPage : ContentPage
{
	public ScanPage()
	{
		InitializeComponent();
        BindingContext = this;

        barcodeView.Options = new ZXing.Net.Maui.BarcodeReaderOptions()
        {
            TryHarder = true,
            AutoRotate = true,
            Multiple = true,
            Formats = BarcodeFormats.TwoDimensional // | ZXing.Net.Maui.BarcodeFormat.QrCode | BarcodeFormat.Pdf417 
        };
        barcodeView.IsTorchOn = true;
	}

    protected void BarcodesDetected(object sender, BarcodeDetectionEventArgs e)
    {
        foreach (var barcode in e.Results)
        { // dumps to Debug.WriteLine()...
            App.Log($"Barcode: {barcode.Format} -> {barcode.Value}");
        }

        var first = e.Results?.FirstOrDefault();
        if (first != null)
        {
            Dispatcher.DispatchAsync(async () =>
            {
                await DisplayAlert("Barcode detected", first.Value, "OK");
            });
        }
    }
}

MauiProgram.cs:

public static class MauiProgram
  {
      public static MauiApp CreateMauiApp()
      {
          var builder = MauiApp.CreateBuilder();
          builder
              .UseMauiApp<App>()
              .UseMauiCommunityToolkit()
              .UseBarcodeReader()
              .ConfigureFonts(fonts =>
              {
                  fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                  fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
              })
              .ConfigureMauiHandlers(handlers =>
              {
                  handlers.AddHandler(typeof(PillCheckbox), typeof(PillCheckboxRenderer));
              });

          builder.Services.AddSingleton<IImageInfo, ImageInfo>();

#if DEBUG
          builder.Logging.AddDebug();
#endif

          var app = builder.Build();

          ServiceProviderHelper.Initialize(app.Services);
          return app;
      }
  }
@chuckgiddens
Copy link

Add

.ConfigureMauiHandlers(h =>
{
h.AddHandler(typeof(CameraBarcodeReaderView),typeof(CameraBarcodeReaderViewHandler));
h.AddHandler(typeof(CameraView), typeof(CameraViewHandler));
h.AddHandler(typeof(BarcodeGeneratorView), typeof(BarcodeGeneratorViewHandler));
});

To MauiProgram.cs

@gtvracer
Copy link
Author

gtvracer commented Apr 8, 2024 via email

@codebeaulieu
Copy link

I'm encountering the same issue. The camera won't pick up anything. When I attempt to feed a high res image into the decoder directly, I get null back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants