afriscic / BarcodeScanning.Native.Maui

Barcode scanning library for .NET MAUI
https://www.nuget.org/packages/BarcodeScanning.Native.Maui
MIT License
195 stars 36 forks source link

thanks afriscic #118

Open elqubed84 opened 4 days ago

elqubed84 commented 4 days ago

Mr. Developer

First of all, thank you very much for the wonderful effort of this innovation

To be honest, it is a very wonderful library in terms of reading speed and image capture speed I really can't describe it

But as you know, your followers are always greedy lol :)

I tried to use the view MVVM , but it didn't work for me

And I think it's largely due to my weak programming experience

Can you put us a code for the view model

And I also hope that the next update will take a picture of the qrcode itself and not the full screen

Because there is definitely a category that will need to pass a picture of the QR code, for example, to make sure there is a logo or something similar for the sake of machine learning

It's just an idea

And for the second time, thank you, thank you :)

niza93 commented 4 days ago

in your XAML: <scanner:CameraView x:Name="qrScanner" TapToFocusEnabled="True" CameraFacing="{Binding CameraFacing}" TorchOn="{Binding TorchOn}" AimMode="{Binding AimMode}" BarcodeSymbologies="QRCode" VibrationOnDetected="False" OnDetectionFinishedCommand="{Binding HandleQRCodeCommand}" PauseScanning="{Binding PauseScanning}"/>

in your viewmodel: public Command HandleQRCodeCommand { get; } private async void HandleQRCode(object o) { if (o is BarcodeResult[] result) { if (result.Length > 0) { if (result[0].BarcodeFormat == BarcodeFormats.QRCode) { PauseScanning = true; Vibration.Vibrate(100); // Handle result[0].DisplayValue here PauseScanning = false; } } } }

in ctor of your vm: HandleQRCodeCommand = new Command(HandleQRCode);

in code-behind of your page: protected override void OnAppearing() { base.OnAppearing(); qrScanner.CameraEnabled = true; } protected override void OnDisappearing() { base.OnDisappearing(); qrScanner.CameraEnabled = false; }

I have not listed other implemented properties here. Also I disabled build-in vibration, because it lasts too long and couldn't be changed.

Hope it will be helpful for your purposes.

niza93 commented 4 days ago

In v1.7.0 and v2.1.0 type of command parameter was changed from BarcodeResult[] to HashSet<BarcodeResult>.

Returning to your recent question (#116), the versions I mentioned in this comment works fine with MAUI v9.0.10 and VisualStudio 17.13.0 Preview 1.0 on Xiaomi 13 device with Android 14.