Git Product home page Git Product logo

zxing.net.maui's Introduction

ZXing.Net.MAUI

The successor to ZXing.Net.Mobile: barcode scanning and generation for .NET MAUI applications

Barcode Scanning

Install ZXing.Net.MAUI

  1. Install ZXing.Net.Maui.Controls NuGet package on your .NET MAUI application

  2. Make sure to initialize the plugin first in your MauiProgram.cs, see below

    // Add the using to the top
    using ZXing.Net.Maui;
    
    // ... other code 
    
    public static MauiApp Create()
    {
    	var builder = MauiApp.CreateBuilder();
    
    	builder
    		.UseMauiApp<App>()
    		.UseBarcodeReader(); // Make sure to add this line
    
    	return builder.Build();
    }

Now we just need to add the right permissions to our app metadata. Find below how to do that for each platform.

Android

For Android go to your AndroidManifest.xml file (under the Platforms\Android folder) and add the following permissions inside of the manifest node:

<uses-permission android:name="android.permission.CAMERA" />

iOS

For iOS go to your info.plist file (under the Platforms\iOS folder) and add the following permissions inside of the dict node:

<key>NSCameraUsageDescription</key>
<string>This app uses barcode scanning to...</string>

Make sure that you enter a clear and valid reason for your app to access the camera. This description will be shown to the user.

Windows

Windows is not supported at this time for barcode scanning. You can however use the barcode generation. No extra permissions are required for that.

For more information on permissions, see the Microsoft Docs.

Using ZXing.Net.Maui

If you're using the controls from XAML, make sure to add the right XML namespace in the root of your file, e.g: xmlns:zxing="clr-namespace:ZXing.Net.Maui.Controls;assembly=ZXing.Net.MAUI.Controls"

<zxing:CameraBarcodeReaderView
  x:Name="cameraBarcodeReaderView"
  BarcodesDetected="BarcodesDetected" />

Configure Reader options

cameraBarcodeReaderView.Options = new BarcodeReaderOptions
{
  Formats = BarcodeFormats.OneDimensional,
  AutoRotate = true,
  Multiple = true
};

Toggle Torch

cameraBarcodeReaderView.IsTorchOn = !cameraBarcodeReaderView.IsTorchOn;

Flip between Rear/Front cameras

cameraBarcodeReaderView.CameraLocation
  = cameraBarcodeReaderView.CameraLocation == CameraLocation.Rear ? CameraLocation.Front : CameraLocation.Rear;

Handle detected barcode(s)

protected void BarcodesDetected(object sender, BarcodeDetectionEventArgs e)
{
  foreach (var barcode in e.Results)
    Console.WriteLine($"Barcodes: {barcode.Format} -> {barcode.Value}");
}

Barcode Generator View

<zxing:BarcodeGeneratorView
  HeightRequest="100"
  WidthRequest="100"
  ForegroundColor="DarkBlue"
  Value="https://dotnet.microsoft.com"
  Format="QrCode"
  Margin="3" />

zxing.net.maui's People

Contributors

carp-kaiser avatar clancey avatar hig-dev avatar jfversluis avatar kfrancis avatar kubaflo avatar lancemccarthy avatar luoyean avatar paoldev avatar pictos avatar prostopsih avatar proudust avatar redth avatar xiz0r avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zxing.net.maui's Issues

Release Device Camera

I'm using the barcode scanner in an app in conjuction with NFC. Depending on the user's preferences, the app can be used to scan either bar codes or NFC tags, respectively. The issue I am now facing is that as soon as I add the bar code scanner to the UI, the NFC scanner won't work - this is a limitation on several Android devices. Removing, hiding or disabling the bar code scanner view does not resolve the issue. I'm curious if there is a way to force the view to release the camera resources in order to enable NFC scanning?

Camera is not disposing

There is an issue after scanning that camera is still on and element not disposing.

IOS green circle still on indicating resource is still in use after changing page or close modal or whatever.

What I tried and nothing is working:
I turned off IsDetecting and set to false after reading.
I also tried to remove the child element it self from stacklayout (it disappears) BUT camera green indicator still show in use.

Please add a Dispose method to manually disconnect the Camera

Set CameraBarcodeReaderView Heigth

I need to have a ListView and the barcode reader below it so that upon detecting it will add the product to the list. I was unable to resize CameraBarcodeReaderView. Is there a possibility?

Failed to read QR code.

The library can't read / detect the following QR code. I was able to read the code with Goolge Lens app on Android.

qr-code-err

No camera rendering on screen

Hi,

I know this is just a rough layout of the project, but after trying it, the camera does not seem to work for Android at least.

I got it to work by changing this line in the CameraManager.android.cs file:

// The Context here SHOULD be something that's a lifecycle owner
	if (Context is AndroidX.Lifecycle.ILifecycleOwner lifecycleOwner)
		camera = cameraProvider.BindToLifecycle(lifecycleOwner, cameraSelector, cameraPreview, imageAnalyzer);

To

// The Context here SHOULD be something that's a lifecycle owner
	if (Context.Context is AndroidX.Lifecycle.ILifecycleOwner lifecycleOwner)
		camera = cameraProvider.BindToLifecycle(lifecycleOwner, cameraSelector, cameraPreview, imageAnalyzer);

Any way to have this working on < API 31 on Android?

I can't seem to get the camera on Android to work on less than API 31 (Android 12), neither in real devices nor emulators... I'd specifically need Android 11, but wondering what is the limiting factor, and if I could make my own compilation (if it's a "release" problem) for API 30

Red Line in the barcode reading - ZXingDefaultOverlay

Hello guys!

I would like to know how do I put the red line in the barcode reading.

In the ZXing.Net.Mobile.Forms library we have zxing:ZXingDefaultOverlay.

How do I do the same function of showing the red line in the ZXing.Net.MAUI library?

Thanks!

Support for iOS 15.5

Hi everyone,
When can we expect support for iOS 15.5? Currently app is breaking on opening view where we do have scan.
Btw best regards to everyone who is making effort to make everything works over here.

Proposal - support for .net6

Hi

We love the scanner so far, keep up the good work.

Would it be possible to include net6.0 support in the package? The maui app I am working on is referenced by a Xunit test project (We have added net6.0 support in the app project using the approach mentioned here. Once we add the package we can no longer compile the project du to the "missing" net6.0 support. Any help or suggestion for a workaround would be highly appreciated.

PixelBufferHolder Data to Image

Hi, great job on the Barcode Reader, I'm very impressed.
I have question, I will like to use CameraView control from ZXing.Net.MAUI for my project and I have problem parsing PixelBufferHolder Data (from CameraFrameBufferEventArgs) to Image. Project is for taking Photos in some sequels and then streaming them to the server for processing, for now just finding edges of documents. So, if this is not much to ask please give me some pointers on how to achieve that goal.

This is my try that ends with file that is not completed 307kb and not possible to be viewed.

        private async void barcodeView_FrameReady(object sender, CameraFrameBufferEventArgs e)
        {
            if (e.Data != null && !IsPhotoTaken)
            {

                byte[] data = null;
#if ANDROID
                var buffer = e.Data.Data;

                data = new byte[buffer.Capacity()];
                e.Data.Data.Rewind();
                _ = buffer.Get(data);
                buffer.Clear();
#elif MACCATALYST || IOS
      
#endif


                var file = await SavePhoto(data, Guid.NewGuid().ToString() + "_test.jpg");

Camera view is not rotating in iOS

Showing the scan view initially works great, but once you rotate the device the camera view does not rotate with the rest of the page in iOS.

In Android the camera view gets flipped around.

For iOS you can see the 2 screenshots:

Portrait

Landscape

Workaround

Couldn't found any workaround.

[Bug & Proposal] doesn't work in FlyoutPage & Init and call directly in C#

When put it inside a FlyoutPage, the CameraBarcodeReaderView doesn't show.

We need to put it in a separate page and navigate to it,
or call it directly in C# (which is way better) like in ZXing.Net.Mobile:

var scanner = new ZXing.Mobile.MobileBarcodeScanner();
var result = await scanner.Scan();
if (result != null)
Console.WriteLine("Scanned Barcode: " + result.Text);

This FlyoutPage scenario might relates to #7, which still exists in latest version (Android 10+; iOS not tested).
No workaround found yet.

Also, could you please put the FlipCamera and ToggleTorch as a standard overlay, so as to make the functionalities easier to be called.

Thanks a lot.
Best Regards

iOS: Add support to change camera resolution

The ability to scan linear barcodes on newer iOS devices is unreliable because the set resolution is too low.
The preset 640x480 results a lot in false values on devices like iPhone 13 Pro.

Since the iPhone 4 the minimum camera resolution is 1080p (or higher) which would work on top devices like the iPhone 13 Pro Max.
Although setting a value too great may crash the app.

Therefore a solution which enables the developer to change the resolution iOS-only would be great e.g. adding another property CameraResolution to BarcodeScanningOptions
Another option would be to read the devices information and take the best possible value

What is your opinion @Redth ?
If you have your handsful I can provide some implementation

how to scan barcode?

I found that when I run your project, I can only recognize the QR code, but not the barcode. I see that your code can recognize the barcode. Why? And can this project also support Windows?

Failed to Read QR Code

using Xamarin can read and try to port to .NET MAUI nothing in the result. Help please

trying read using Scandit and able to read.
below is the qrcode

test2

How to run on MAUI app

I am new to MAUI app, i am trying to run this on my razor page. Can somebody help me out? This is my current code below.
I got error saying that:

Error (active) CS0246 The type or namespace name 'BarcodeDetectionEventArgs' could not be found (are you missing a using directive or an assembly reference?) MauiAppBlazor (net6.0-android)

@page "/counter"
@using ZXing.Mobile

<zxing:CameraBarcodeReaderView x:Name="cameraBarcodeReaderView"
                               BarcodesDetected="BarcodesDetected" />

@code {
    public void BarcodesDetected(object sender, BarcodeDetectionEventArgs e)
    {
    if (e is null)
    {
        throw new ArgumentNullException(nameof(e));
    }

    foreach (var barcode in e.Results)
        //Console.WriteLine($"Barcodes: {barcode.Format} -> {barcode.Value}");
    }
}

Why zxing shows black screen in .net maui?

Hi team,

I'm trying to use the bar code scanning ZXing.Net.Maui

I add the scanner to a page as follows :

	<?xml version="1.0" encoding="utf-8" ?>
	<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
				 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
				 x:Class="myapp.Pages.ControleDesBillets"
				 x:DataType="viewmodel:StandardPageVM"
				 xmlns:viewmodel="clr-namespace:myapp.ViewModels"
				 xmlns:Controls="clr-namespace:myapp.Resources.Controls"             
				 xmlns:zxing="clr-namespace:ZXing.Net.Maui.Controls;assembly=ZXing.Net.MAUI">

		<Grid RowDefinitions="*" ColumnDefinitions="*">
			<zxing:CameraBarcodeReaderView x:Name="cameraBarcodeReaderView" Grid.Column="0" Grid.Row="0" HeightRequest="200" WidthRequest="200"/>
		</Grid>

	</ContentPage>

When the app runs, it prompts for the Camera Access which is allowed then it shows a black screen and nothing else.

The scanner is initialized in the start up of the app :

	public static MauiApp CreateMauiApp()
	{
		var builder = MauiApp.CreateBuilder();

		builder.UseMauiApp<App>().UseMauiCommunityToolkit();
		builder.UseBarcodeReader();  // << here
		return builder.Build();
	}		

I'm testing using a physical device. Here is my output :

	Loaded assembly: /data/data/com.companyname.myapp/files/.__override__/Xamarin.Google.Guava.ListenableFuture.dll [External]
	[CameraManagerGlobal] Connecting to camera service
	[CameraManagerGlobal] [soar.cts] ignore the status update of camera: 2
	[CameraManagerGlobal] [soar.cts] ignore the status update of camera: 3
	[CameraManagerGlobal] [soar.cts] ignore the status update of camera: 4
	[CameraManagerGlobal] [soar.cts] ignore the status update of camera: 5
	[CameraManagerGlobal] ignore the torch status update of camera: 3
	[CameraManagerGlobal] ignore the torch status update of camera: 4
	[CameraMetadataJV] setAppNameAndSensorId all [com.antutu:0,ssize,12032x9024,0,false]
	[CameraMetadataJV] setAppNameAndSensorId all [com.antutu:1,ssize,5184x3880,0,false]
	[CameraRepository] Added camera: 0
	[Camera2CameraInfo] Device Level: INFO_SUPPORTED_HARDWARE_LEVEL_3
	[CameraRepository] Added camera: 1
	[Camera2CameraInfo] Device Level: INFO_SUPPORTED_HARDWARE_LEVEL_3
	[CameraValidator] Verifying camera lens facing on rain, lensFacingInteger: null
	Thread finished: <Thread Pool> #2
	Thread finished: <Thread Pool> #4
	Le thread 0x2 s'est arrêté avec le code 0 (0x0).
	Le thread 0x4 s'est arrêté avec le code 0 (0x0).
	[CompatibilityChangeReporter] Compat change id reported: 150939131; UID 10378; state: ENABLED

Does anyone know what am I doing wrong please ?

Thanks.
Cheers,

The type or namespace name 'Controls' does not exist

Hi,

I don't know why I started getting the below message in 0.2.0-preview.2

Error CS0234: The type or namespace name 'Controls' does not exist in the namespace 'ZXing.Net.Maui' (are you missing an assembly reference?) (CS0234)

This is the line throwing the error:

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

Kindly help..

Thanks,
Jassim

Zxing MAUI not working on Samsung Tab

Hi,

I am trying to use Zxing MAUI on Samsung Tab A7 SM-T500 but the scanning is not happening and BarcodesDetected is not fired.

Kindly help..

Thanks,
Jassim

Missing library

Hello

After install:
NuGet\Install-Package ZXing.Net.Maui -Version 0.2.0-preview.1

using ZXing.Net.Maui;

// ... other code 

public static MauiApp Create()
{
	var builder = MauiApp.CreateBuilder();

	builder
		.UseMauiApp<App>()
		.UseBarcodeReader(); // Make sure to add this line

	return builder.Build();
}

After this code I have an error on UseBarcodeReader:
'xxxx' does not contain a definition for 'UseBarcodeReader' and no accessible extension method 'UseBarcodeReader' accepting a first argument of type 'xxxx' could be found (are you missing a using directive or an assembly reference?).

In the xaml file after:
xmlns:zxing="clr-namespace:ZXing.Net.Maui.Controls;assembly=ZXing.Net.MAUI"

Have an issue on Controls that seems missing.

Very thanks for your support

Invisible to Visible not working properly

Firstly, great work!

I would like to have the scanning camera invisible to start with. I tap a button and then the scanning camera becomes visible and active. As soon as it detects a QR Code, I make the scanning camera invisible again.

The above works fine if the default is that the scanning is visible at start-up. I can then make the camera visible again and repeat over and over, which is good. The problem is that if the camera is initially invisible (as I need it), it does not appear when I make it visible, which is strange! This is on a Samsung Cover Pro phone running Android 12.

Call barcode reader from code behind

I'm using this library for my Xamarin.Forms apps.
There, I used to get the barcode via following code snippet.

MobileBarcodeScanner scanner = new()
                    {
                        UseCustomOverlay = false
                    };
                    ZXing.Result result = await scanner.Scan();
                    if (result != null)
                        var myBC = result.Text;

How do I achive the same with the MAUI version?
Thanks for helping out!

Scan for android

Java.Lang.IllegalStateException: 'Unexpected rotation value -1'

Quits unexpectedly as soon as it runs, but I don't do anything
Can it select a photo and Automatic Identification?

net7.0 support

I am trying to use the nuget package with targetframework 7.0 but I am getting the error, it is not compatible with net7.0.

Is there any chance how to use this project under 7.0?

com.android.tools.r8.CompilationFailedException: Compilation failed to complete

I get this error when I try to build the project on Visual Studio 2022 v 17.2.0 Preview 1.0

java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: C:\Users\App Lab Developer.nuget\packages\xamarin.google.guava.listenablefuture\1.0.0.5\buildTransitive\net6.0-android31.0....\jar\guava-listenablefuture.jar : com/google/common/util/concurrent/ListenableFuture.class
BigIslandBarcode C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.200-preview.13.41\tools\Xamarin.Android.D8.targets 79

1D barcode only reads in vertical orientation

When scanning 1D barcodes, the camera only reads the barcode when it's in a vertical orientation (rotated vertically). This does not happen with QR codes where camera can pick up any orientation of the QR code. This happens on Android physical device

How to use in .Net MAUI Blazor (Blazor Hybrid)

Would be great help if some one can share code how to use in .net maui blazor app(blazor hybrid).
Will Zxing.Net.Maui will support all previous version of android like form 7 onward to 12? or only some specific version.

Not working inside a tab page

When placed inside a tab page, the scanner initially works well. When navigating to another tab and back, the scanner remains blank.

Calling InitializeComponent() in OnAppearing() will solve the scanner issue but the Torch will stop working.

How to use BarcodeResult.Raw

I need to know if the barcode contains some special characters, like GS for a GS1-128 barcode.
I tried decoding the Raw property, but I cannot find a way to understand what's inside that byte[].
I would need to translate it to ascii characters to check for GS (ASCII 29). Is it possible?

Missing Namespace 'Controls' in 0.2.0 preview.1

The 'Controls' Namespace is missing in version 0.2.0 preview.1. I get the following error:
Error CS0234 The type or namespace name 'Controls' does not exist in the namespace 'ZXing.Net.Maui' (are you missing an assembly reference?).

ZXing for MAUI Nuget Package release please

Hi Redth,
ZXing for Xamarin is awesome. As the GA of MAUI is near, we would like to migrate apps to MAUI.
Could you please publish a Nuget Package for this wonderful code scanner lib?
Thanks a lot!

Best Regards

maximumViewportInset cannot be larger than frame iOS error

Hoping you can help.
I am getting the following error on start up in an iOS simulator.
The app works fine in Android.
If I remove the Barcode xaml, the app starts up properly.
I have added my permission to my plist.
I upgraded to .net7 from 6 to no avail.
I upgraded the ZXIng reader to 0.1.0-preview.7 but could not get anything higher to work because I am targeting IOS 15.5.

image

This is the device output:

2022-10-26 21:05:25.904431-0500 SMobile[14236:148430] [unspecified] container_system_group_path_for_identifier: error = ((container_error_t)98) NOT_CODESIGNED
Error getting system group container for systemgroup.com.apple.configurationprofiles: 98
Failed to get profile system group container path. Overriding with expected path: /Users/macminim1/Library/Developer/CoreSimulator/Devices/0B8BF9E6-58A1-430F-A8EB-0E8B421193A9/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
SecTaskLoadEntitlements failed error=22 cs_flags=200, pid=14236
SecTaskCopyDebugDescription: SMobile[14236]/0#-1 LF=0
SecTaskLoadEntitlements failed error=22 cs_flags=200, pid=14236
SecTaskCopyDebugDescription: SMobile[14236]/0#-1 LF=0
SecTaskLoadEntitlements failed error=22 cs_flags=200, pid=14236
SecTaskCopyDebugDescription: SMobile[14236]/0#-1 LF=0
[ViewportSizing] maximumViewportInset cannot be larger than frame
ViewportSizing] minimumViewportInset cannot be larger than frame

This is the exception:

System.ArgumentNullException: Value cannot be null. (Parameter 'device')
  at at ObjCRuntime.ThrowHelper.ThrowArgumentNullException(String argumentName)
  at at ObjCRuntime.NativeObjectExtensions.GetNonNullHandle(INativeObject self, String argumentName)
  at at AVFoundation.AVCaptureDeviceInput..ctor(AVCaptureDevice device, NSError& error)
  at at ZXing.Net.Maui.CameraManager.UpdateCamera()
  at at ZXing.Net.Maui.CameraManager.UpdateCameraLocation(CameraLocation cameraLocation)
  at at ZXing.Net.Maui.CameraBarcodeReaderViewHandler.<>c.<.cctor>b__24_1(CameraBarcodeReaderViewHandler handler, ICameraBarcodeReaderView virtualView)
  at at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[ZXing.Net.Maui.ICameraBarcodeReaderView, ZXing.Net.MAUI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[ZXing.Net.Maui.CameraBarcodeReaderViewHandler, ZXing.Net.MAUI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v)
  at at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView)
  at at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView)
  at at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view)
  at at Microsoft.Maui.Handlers.ViewHandler`2[[ZXing.Net.Maui.ICameraBarcodeReaderView, ZXing.Net.MAUI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[UIKit.UIView, Microsoft.iOS, Version=15.4.700.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].SetVirtualView(IView view)
  at at Microsoft.Maui.Handlers.ViewHandler`2[[ZXing.Net.Maui.ICameraBarcodeReaderView, ZXing.Net.MAUI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[UIKit.UIView, Microsoft.iOS, Version=15.4.700.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].SetVirtualView(IElement view)
  at at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler)
  at at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value)
  at at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value)
  at at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context)
  at at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context)
  at at Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView(IView view)
  at at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.ILayout, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.LayoutView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view)
  at at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler)
  at at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value)
  at at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value)
  at at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context)
  at at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context)
  at at Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView(IView view)
  at at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.ILayout, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.LayoutView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view)
  at at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler)
  at at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value)
  at at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value)
  at at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context)
  at at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context)
  at at Microsoft.Maui.Handlers.ContentViewHandler.UpdateContent(IContentViewHandler handler)
  at at Microsoft.Maui.Handlers.ContentViewHandler.MapContent(IContentViewHandler handler, IContentView page)
  at at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IContentViewHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v)
  at at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView)
  at at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView)
  at at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view)
  at at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IView view)
  at at Microsoft.Maui.Handlers.ContentViewHandler.SetVirtualView(IView view)
  at at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view)
  at at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler)
  at at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value)
  at at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value)
  at at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context)
  at at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context)
  at at Microsoft.Maui.Platform.ElementExtensions.ToUIViewController(IElement view, IMauiContext context)
  at at Microsoft.Maui.Handlers.WindowHandler.MapContent(IWindowHandler handler, IWindow window)
  at at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.IWindow, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IWindowHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v)
  at at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView)
  at at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView)
  at at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view)
  at at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler)
  at at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value)
  at at Microsoft.Maui.Platform.ElementExtensions.SetHandler(INativeObject nativeElement, IElement element, IMauiContext context)
  at at Microsoft.Maui.Platform.ElementExtensions.SetWindowHandler(UIWindow platformWindow, IWindow window, IMauiContext context)
  at at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(IApplication application, UIWindowScene windowScene, NSDictionary[] states)
  at at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(IUIApplicationDelegate platformApplication, IApplication application, UIApplication uiApplication, NSDictionary launchOptions)
  at at Microsoft.Maui.MauiUIApplicationDelegate.FinishedLaunching(UIApplication application, NSDictionary launchOptions)
  at at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass)
  at SMobile.Program.Main(String[] args) in /Users/macminim1/Projects/Sorted/SMobile/SMobile/Platforms/iOS/Program.cs:13

My XAML:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:b="clr-namespace:Microsoft.AspNetCore.Components.WebView.Maui;assembly=Microsoft.AspNetCore.Components.WebView.Maui"
             xmlns:local="clr-namespace:SMobile"
             xmlns:data="clr-namespace:SMobile.Data"
             xmlns:zxing="clr-namespace:ZXing.Net.Maui.Controls;assembly=ZXing.Net.MAUI"
             x:Class="SMobile.MainPage"
             BackgroundColor="{DynamicResource PageBackgroundColor}">

    <ContentPage.Resources>
        <data:ShowQrReaderConverter x:Key="ShowQrReaderConverter"/>
        <data:ShowFrCapturingConverter x:Key="ShowFrCapturingConverter"/>
    </ContentPage.Resources>

    <AbsoluteLayout>
        <b:BlazorWebView HostPage="wwwroot/index.html" 
                         AbsoluteLayout.LayoutBounds="0, 0, 1, 1" 
                         AbsoluteLayout.LayoutFlags="All">
            <b:BlazorWebView.RootComponents>
                <b:RootComponent Selector="#app" ComponentType="{x:Type local:Main}" />
            </b:BlazorWebView.RootComponents>
        </b:BlazorWebView>

        <!-- QR Reader -->
        <AbsoluteLayout
            x:Name="absLayout"
            Margin="0,334"
            BackgroundColor="Beige"
            HeightRequest="{Binding availableQrReaderHeight}"
            WidthRequest="{Binding availableQrReaderWidth}"
            >
            <AbsoluteLayout.TranslationX>
                <MultiBinding Converter="{StaticResource ShowQrReaderConverter}">
                    <Binding Path="CardToggle" />
                    <Binding Path="qrReaderDetecting" />
                    <Binding Path="AppState.ShootMode" />
                </MultiBinding>
            </AbsoluteLayout.TranslationX>

            <zxing:CameraBarcodeReaderView
                x:Name="barcodeReader"
                IsDetecting="{Binding qrReaderDetecting}"
                IsVisible="{Binding qrReaderVisible}"
                IsTorchOn="False" 
                BarcodesDetected="CameraBarcodeReaderView_BarcodesDetected"
                >
            </zxing:CameraBarcodeReaderView>
            
        </AbsoluteLayout>

    </AbsoluteLayout>
</ContentPage>

My Plist
image

Goes Black when using NavigationPage

Only way atm to use the components is by setting the MainPage manually, when pushing and poping using navigation it will cause the component not to initialize.

Problem with FNC1 separator character in Code128

Hello, I've try reading a Code128 linear barcode, and it appears that the barcoderesult didn't return the GS (groupe separator 0x1d) byte inside the returned string. The Same test with Datamatrix work perfectly. Didn't try other barcode specific encoding.
Datamatrix vs Code128

How to use it in MAUI Blazor project

After importing the nuget package, adding .UseBarcodeReader(); and adding the namespace to the razor file, once I add the control

<CameraBarcodeReaderView x:Name="cameraBarcodeReaderView" BarcodesDetected="BarcodesDetected"  />

Visual Studio shows:
"Found markup element with unexpected name."

=> Visual Studio cannot find the control in order to use it in the razor file.

  • Is this a known issue?
  • What's the correct way to use ZXing.Net.Maui in a MAUI Blazor app?

Resources Build Action

To be able to run the example I had to change the Build Action from the resources to MauiFont and MauiImage in the images.

Error when using UseBarcodeReader(); in MauiProgram.cs

I was using this package for Barcode scanning. But after update to 0.2.0-preview.2 getting build error.

Error CS1061 'MauiAppBuilder' does not contain a definition for 'UseBarcodeReader' and no accessible extension method 'UseBarcodeReader' accepting a first argument of type 'MauiAppBuilder' could be found (are you missing a using directive or an assembly reference?) Barcodescanner (net6.0-android), Barcodescanner (net6.0-ios), Barcodescanner (net6.0-maccatalyst), Barcodescanner (net6.0-windows10.0.19041.0)

Barcodescanner.zip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.