BarcodeScanning.Native.Maui
2.1.2
dotnet add package BarcodeScanning.Native.Maui --version 2.1.2
NuGet\Install-Package BarcodeScanning.Native.Maui -Version 2.1.2
<PackageReference Include="BarcodeScanning.Native.Maui" Version="2.1.2" />
paket add BarcodeScanning.Native.Maui --version 2.1.2
#r "nuget: BarcodeScanning.Native.Maui, 2.1.2"
// Install BarcodeScanning.Native.Maui as a Cake Addin #addin nuget:?package=BarcodeScanning.Native.Maui&version=2.1.2 // Install BarcodeScanning.Native.Maui as a Cake Tool #tool nuget:?package=BarcodeScanning.Native.Maui&version=2.1.2
BarcodeScanning.Native.Maui
Barcode scanning library based on native platform APIs for barcode detection:
This library was inspired by existing MAUI barcode scanning libraries: BarcodeScanner.Mobile & Zxing.Net.MAUI, but comes with many code improvements and uses native ML APIs on both Android and iOS/macOS.
Key features
- Uses native APIs for maximal performance and barcode readability,
- Optimized for continuous scanning,
- Ability to scan multiple barcodes in one frame,
- Ability to pool multiple scans for better scanning consistency,
- Transformed barcode bounding box for on-screen positioning,
- From version 1.2.0 implemented
ViewfinderMode
- detect only barcodes present in camera preview on screen andAimMode
- detect only the barcode that is overlapped with the red dot centred in camera preview, - From version 1.4.1 ability to control camera zoom and camera selection on supported multi-camera setups on iOS and Android,
- From version 1.5.0 ability to save images from the camera feed.
- Code-behind and MVVM compatibility,
- Android only - Ability to invert source image to scan natively unsupported inverted barcodes, but at a performance cost.
Usage
- Install Nuget package,
- Initialize the plugin in your
MauiProgram.cs
:public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder ... .UseBarcodeScanning(); ... return builder.Build(); }
- Add required permissions:
Android
EditAndroidManifest.xml
file (under the Platforms\Android folder) and add the following permissions inside of themanifest
node:<uses-permission android:name="android.permission.CAMERA" />
iOS/macOS
Editinfo.plist
file (under the Platforms\iOS or Platforms\MacCatalyst folder) and add the following permissions inside of thedict
node:
And ask for permission from user in your code:<key>NSCameraUsageDescription</key> <string>Enable camera for barcode scanning.</string>
await Methods.AskForRequiredPermissionAsync();
- In XAML, add correct namespace, for example:
xmlns:scanner="clr-namespace:BarcodeScanning;assembly=BarcodeScanning.Native.Maui"
- Set the
CameraEnabled
property totrue
in XAML, code behind or ViewModel to start the camera. As a best practice set it inOnAppearing()
method override in your ContentPage. - Listen to
OnDetectionFinished
event in Code-behind:<scanner:CameraView ... OnDetectionFinished="CameraView_OnDetectionFinished" .../>
or bindprivate void CameraView_OnDetectionFinished(object sender, OnDetectionFinishedEventArg e) { if (e.BarcodeResults.Count > 0) ... }
OnDetectionFinishedCommand
property to a Command in your ViewModel:<scanner:CameraView ... OnDetectionFinishedCommand="{Binding DetectionFinishedCommand}" .../>
public ICommand DetectionFinishedCommand { get; set; } ... DetectionFinishedCommand = new Command<IReadOnlySet<BarcodeResult>>(IReadOnlySet<BarcodeResult> result) => { if (result.Count > 0) ... }
- As a best practice set the
CameraEnabled
property tofalse
inOnDisappearing()
method override in your ContentPage. - From .NET MAUI 9 (version 2.0.0) manually calling
DisconnectHandler()
is no loger required, but optional. More info here: What's new in .NET MAUI for .NET 9 - From version 1.5.0 set the
CaptureNextFrame
property totrue
to capture next frame from the camera feed as aPlatformImage
. Listen toOnImageCaptured
event or bind toOnImageCapturedCommand
property to get the caputured image. Image is captured from the original camera feed and can be different from the on-screen preview. After the image is capturedCaptureNextFrame
property is automaticly set tofalse
to prevent memory leaks. Example can be found inScanTab.xaml.cs
.
Supported barcode symbologies
Android
1D: Codabar, Code 39, Code 93, Code 128, EAN-8, EAN-13, ITF, UPC-A, UPC-E; 2D: Aztec, Data Matrix, PDF417, QR Code
iOS/macOS
1D: Codabar, Code 39, Code 93, Code 128, EAN-8, EAN-13, GS1 DataBar, ITF, UPC-A, UPC-E; 2D: Aztec, Data Matrix, MicroPDF417, MicroQR, PDF417, QR Code
Bindable properties
A list of bindable properties with descriptions can be found in CameraView.cs source file.
TODO Windows support
Windows is currently unsupported, but support can be added in the future through Zxing.Net project.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android35.0 is compatible. net9.0-ios18.0 is compatible. net9.0-maccatalyst18.0 is compatible. |
-
net9.0
- Microsoft.Maui.Controls (>= 9.0.0)
-
net9.0-android35.0
- Microsoft.Maui.Controls (>= 9.0.0)
- Xamarin.AndroidX.Activity.Ktx (>= 1.9.3.1)
- Xamarin.AndroidX.Camera.Camera2 (>= 1.4.0.2)
- Xamarin.AndroidX.Camera.View (>= 1.4.0.2)
- Xamarin.AndroidX.Collection.Ktx (>= 1.4.5.1)
- Xamarin.AndroidX.Fragment.Ktx (>= 1.8.5.1)
- Xamarin.Google.MLKit.BarcodeScanning (>= 117.3.0.1)
-
net9.0-ios18.0
- Microsoft.Maui.Controls (>= 9.0.0)
-
net9.0-maccatalyst18.0
- Microsoft.Maui.Controls (>= 9.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on BarcodeScanning.Native.Maui:
Package | Downloads |
---|---|
OpenMAUIAndroid
Uma lib de leitura de código de barras que agrupa os mais diversos SDKs e EMDKs de fabricantes de coletores de dados, e gerencia tudo de forma automática. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.1.2 | 33 | 12/4/2024 |
2.1.1 | 636 | 11/25/2024 |
2.0.1 | 562 | 11/19/2024 |
2.0.0 | 279 | 11/18/2024 |
1.7.2 | 26 | 12/4/2024 |
1.7.1 | 400 | 11/25/2024 |
1.6.0 | 2,063 | 11/11/2024 |
1.5.9 | 3,980 | 10/19/2024 |
1.5.8 | 4,466 | 10/1/2024 |
1.5.7 | 27,498 | 7/11/2024 |
1.5.6 | 9,243 | 6/19/2024 |
1.5.5 | 1,267 | 6/12/2024 |
1.5.3 | 3,129 | 5/24/2024 |
1.5.2 | 1,494 | 5/17/2024 |
1.5.0 | 12,547 | 4/20/2024 |
1.4.3 | 1,265 | 4/11/2024 |
1.4.2 | 1,421 | 4/4/2024 |
1.4.1 | 1,705 | 3/22/2024 |
1.4.0 | 577 | 3/17/2024 |
1.3.1 | 3,081 | 3/13/2024 |
1.3.0 | 152 | 3/13/2024 |
1.2.5 | 687 | 3/8/2024 |
1.2.4 | 6,159 | 1/24/2024 |
1.2.3 | 1,315 | 1/9/2024 |
1.2.2 | 798 | 12/27/2023 |
1.2.1 | 362 | 12/20/2023 |
1.2.0 | 364 | 12/17/2023 |
1.1.1 | 354 | 12/6/2023 |
1.1.0 | 320 | 12/4/2023 |
1.0.3 | 284 | 11/27/2023 |
1.0.2 | 443 | 11/24/2023 |
1.0.1 | 296 | 11/16/2023 |
0.9.3 | 5,224 | 4/19/2023 |
0.9.1 | 261 | 3/31/2023 |