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.
- 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.
- 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:
Edit
AndroidManifest.xml
file (under the Platforms\Android folder) and add the following permissions inside of themanifest
node:Edit<uses-permission android:name="android.permission.CAMERA" />
info.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
.
1D: Codabar, Code 39, Code 93, Code 128, EAN-8, EAN-13, ITF, UPC-A, UPC-E; 2D: Aztec, Data Matrix, PDF417, QR Code
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
A list of bindable properties with descriptions can be found in CameraView.cs source file.
Windows is currently unsupported, but support can be added in the future through Zxing.Net project.