Open Uridel opened 6 months ago
Update: I appears to only be a problem on Android, iOS seems to be working fine.
Same issue on Android
BarcodeDetected is never fired with latest version
Can confirm that versions 1.5.1 and 1.5.0 for iOS and Android has stopped scanning any barcodes (QR, Data Matrix, Code 128 etc.)
Reverting to 1.44 and ZXing.BarcodeFormat
in the PossibleFormats
settings works as expected.
@hjam40 are you aware that barcode scanning currently doesn't work?
Hi @Uridel,
Barcode scanning is working fine in the 1.5.1 version. Here you can see my tests.
Windows QR: Android EAN13:
Maybe you could take a look to the new readme for how to use the new plugging. The new property BarCodeDecoder must be initiated: cameraView.BarCodeDecoder = new ZXingBarcodeDecoder();
I've spent half a day, trying to get barcode scanning to work. Camera.MAUI 1.5.1, Android 10 I've found, that if WidthRequest and HeightRequest attributes on CameraView are missing, then barcode scanning is breaked.
<cv:CameraView x:Name="cameraView" WidthRequest="300" HeightRequest="300" />
Working code:
<?xml version="1.0" encoding="utf-8" ?>
<mct:Popup xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mct="clr-namespace:CommunityToolkit.Maui.Views;assembly=CommunityToolkit.Maui"
xmlns:cv="clr-namespace:Camera.MAUI;assembly=Camera.MAUI"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
x:Class="FiscalCloud.Mobile.BarcodeScannerPopupPage" Opened="Popup_Opened" Closed="Popup_Closed">
<Grid>
<toolkit:MediaElement x:Name="beepMediaElement" IsVisible="false"
Source="embed://beep.mp3" />
<cv:CameraView x:Name="cameraView" WidthRequest="300" HeightRequest="300" />
</Grid>
</mct:Popup>
public BarcodeScannerPopupPage()
{
InitializeComponent();
cameraView.CamerasLoaded += cameraView_CamerasLoaded;
cameraView.BarcodeDetected += cameraView_BarcodeDetected;
cameraView.BarCodeDecoder = new ZXingBarcodeDecoder();
cameraView.BarCodeOptions = new BarcodeDecodeOptions
{
AutoRotate = true,
PossibleFormats = { BarcodeFormat.QR_CODE, BarcodeFormat.All_1D },
ReadMultipleCodes = false,
TryHarder = false,
TryInverted = true
};
cameraView.BarCodeDetectionEnabled = true;
}
private void cameraView_CamerasLoaded(object? sender, EventArgs e)
{
if (cameraView.Cameras.Count > 0)
{
cameraView.Camera = cameraView.Cameras.First();
MainThread.BeginInvokeOnMainThread(async () =>
{
await cameraView.StopCameraAsync();
await cameraView.StartCameraAsync();
});
}
}
private void cameraView_BarcodeDetected(object? sender, BarcodeEventArgs args)
{
MainThread.BeginInvokeOnMainThread(() =>
{
foreach (var result in args.Result)
{
if (string.IsNullOrWhiteSpace(result.Text))
continue;
PlayBeep();
barcodeDetectedCallback.Invoke(result.Text);
}
});
}
I've spent half a day, trying to get barcode scanning to work. Camera.MAUI 1.5.1, Android 10 I've found, that if WidthRequest and HeightRequest attributes on CameraView are missing, then barcode scanning is breaked.
<cv:CameraView x:Name="cameraView" WidthRequest="300" HeightRequest="300" />
Working code:
<?xml version="1.0" encoding="utf-8" ?> <mct:Popup xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:mct="clr-namespace:CommunityToolkit.Maui.Views;assembly=CommunityToolkit.Maui" xmlns:cv="clr-namespace:Camera.MAUI;assembly=Camera.MAUI" xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" x:Class="FiscalCloud.Mobile.BarcodeScannerPopupPage" Opened="Popup_Opened" Closed="Popup_Closed"> <Grid> <toolkit:MediaElement x:Name="beepMediaElement" IsVisible="false" Source="embed://beep.mp3" /> <cv:CameraView x:Name="cameraView" WidthRequest="300" HeightRequest="300" /> </Grid> </mct:Popup>
public BarcodeScannerPopupPage() { InitializeComponent(); cameraView.CamerasLoaded += cameraView_CamerasLoaded; cameraView.BarcodeDetected += cameraView_BarcodeDetected; cameraView.BarCodeDecoder = new ZXingBarcodeDecoder(); cameraView.BarCodeOptions = new BarcodeDecodeOptions { AutoRotate = true, PossibleFormats = { BarcodeFormat.QR_CODE, BarcodeFormat.All_1D }, ReadMultipleCodes = false, TryHarder = false, TryInverted = true }; cameraView.BarCodeDetectionEnabled = true; } private void cameraView_CamerasLoaded(object? sender, EventArgs e) { if (cameraView.Cameras.Count > 0) { cameraView.Camera = cameraView.Cameras.First(); MainThread.BeginInvokeOnMainThread(async () => { await cameraView.StopCameraAsync(); await cameraView.StartCameraAsync(); }); } } private void cameraView_BarcodeDetected(object? sender, BarcodeEventArgs args) { MainThread.BeginInvokeOnMainThread(() => { foreach (var result in args.Result) { if (string.IsNullOrWhiteSpace(result.Text)) continue; PlayBeep(); barcodeDetectedCallback.Invoke(result.Text); } }); }
Can confirm, had the same issue until I've set the dimensions to the CameraView as well, since I have it wrapped in a Border I had the WidthRequest and HeightRequest there and not in the CameraView since for the layout it was unnecessary.
Works
<Border Stroke="Black" StrokeThickness="1">
<cv:CameraView x:Name="cameraView" CamerasLoaded="cameraView_CamerasLoaded" Loaded="cameraView_Loaded" WidthRequest="300" HeightRequest="300"/>
</Border>
Doesn't work
<Border Stroke="Black" StrokeThickness="1" WidthRequest="300" HeightRequest="300">
<cv:CameraView x:Name="cameraView" CamerasLoaded="cameraView_CamerasLoaded" Loaded="cameraView_Loaded"/>
</Border>
Bit late, but yes. Settings the width and height seems to fix it. @hjam40 , is there known reason to this sudden change, previous versions of the library didn't require Width/Height requests in order to scan 1D barcodes
Why version 1.2.1 is much faster at detecting barcodes and QR codes than the latest version? and no need to install Camera.MAUI.ZXing to detect barcode
Why version 1.2.1 is much faster at detecting barcodes and QR codes than the latest version? and no need to install Camera.MAUI.ZXing to detect barcode
How much faster is it? Is it noticeably faster? What futures does it lack?
For those that like me want the CameraView to fit the size of the container and ran into this issue, quick and dirty solution is to wrap it with a Grid or another container of your choice, name it, then Bind your dimensions into its Width and Height:
<Grid x:Name="cameraViewContainer">
<cv:CameraView x:Name="cameraView" WidthRequest="{Binding Source={x:Reference cameraViewContainer}, Path=Width}" HeightRequest="{Binding Source={x:Reference cameraViewContainer}, Path=Height}"/>
</Grid>
If the size requirements get removed in a future update, this workaround should still work.
Why version 1.2.1 is much faster at detecting barcodes and QR codes than the latest version? and no need to install Camera.MAUI.ZXing to detect barcode
How much faster is it? Is it noticeably faster? What futures does it lack?
It can scan barcodes like just a second unlike the latest version which taking forever and most of the time, not able to scan at all. I will be preparing a comparison and will make another thread for this one
How did you solve this @info-ajdragasa ? We tried downgrade to 1.2.1 and looks a lot faster yeah. @skane526
I still cannot scan 1D barcodes on Android for some reason (v1.5.1). I have set the Width and Height request as suggested and can scan 2D codes (even though extremely finicky with distance from camera). The weird thing for me is the only codes detected are 2D when I have PossibleFormats = { BarcodeFormat.All_1D }...
I still cannot scan 1D barcodes on Android for some reason (v1.5.1). I have set the Width and Height request as suggested and can scan 2D codes (even though extremely finicky with distance from camera). The weird thing for me is the only codes detected are 2D when I have PossibleFormats = { BarcodeFormat.All_1D }...
I would suggest you doing a rollback to 1.3.5, that's what I ended up doing. 1.5.1 has worse performance, it takes a while with stopping and starting the camera, image quality is bad compared to 1.3.5 despite selecting the highest res option and it takes forever to detect a code.
1.3.5 does all the above better, for now.
camera started but barcode detection does not run at all!
I'm having this issue even though I have set WidthRequest and HeightRequest. It scans QR codes but no 1D barcodes that I can find.
I updated to the latest version of Camera.Maui and Camera.Maui.ZXing. However I have noticed that barcode detection for anything besides QR_Code just doesn't seem to work.
I tried to verify whether I was incorrectly implementing the setup. So I downloaded the test project from Github and ran it. I simply added the
BarcodeFormat.All_1D
to theFullScreenPage.xaml.cs
expecting it to work. But it doesn't theBarcodeDetected
event simply is not fired.Is anyone else experiencing this?