BarcodeScanning.Native.Maui 1.5.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package BarcodeScanning.Native.Maui --version 1.5.6                
NuGet\Install-Package BarcodeScanning.Native.Maui -Version 1.5.6                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BarcodeScanning.Native.Maui" Version="1.5.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BarcodeScanning.Native.Maui --version 1.5.6                
#r "nuget: BarcodeScanning.Native.Maui, 1.5.6"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install BarcodeScanning.Native.Maui as a Cake Addin
#addin nuget:?package=BarcodeScanning.Native.Maui&version=1.5.6

// Install BarcodeScanning.Native.Maui as a Cake Tool
#tool nuget:?package=BarcodeScanning.Native.Maui&version=1.5.6                

BarcodeScanning.Native.Maui

Barcode scanning library based on native platform APIs for barcode detection:

  1. Google ML Kit
  2. Apple Vision framework

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

  1. Uses native APIs for maximal performance and barcode readability,
  2. Optimized for continuous scanning,
  3. Ability to scan multiple barcodes in one frame,
  4. Ability to pool multiple scans for better scanning consistency,
  5. Transformed barcode bounding box for on-screen positioning,
  6. From version 1.2.0 implemented ViewfinderMode - detect only barcodes present in camera preview on screen and AimMode - detect only the barcode that is overlapped with the red dot centred in camera preview,
  7. From version 1.4.1 ability to control camera zoom and camera selection on supported multi-camera setups on iOS and Android,
  8. From version 1.5.0 ability to save images from the camera feed.
  9. Code-behind and MVVM compatibility,
  10. Android only - Ability to invert source image to scan natively unsupported inverted barcodes, but at a performance cost.

Usage

  1. Install Nuget package,

  2. Initialize the plugin in your MauiProgram.cs:

    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder
            ...
            .UseBarcodeScanning();
            ...
    
        return builder.Build();
    }
    
  3. Add required permissions:

    Android

    Edit 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/macOS

    Edit info.plist file (under the Platforms\iOS or Platforms\MacCatalyst folder) and add the following permissions inside of the dict node:

    <key>NSCameraUsageDescription</key>
    <string>Enable camera for barcode scanning.</string>
    

    And ask for permission from user in your code:

    await Methods.AskForRequiredPermissionAsync();
    
  4. In XAML, add correct namespace, for example:

    xmlns:scanner="clr-namespace:BarcodeScanning;assembly=BarcodeScanning.Native.Maui"
    
  5. Set the CameraEnabled property to true in XAML, code behind or ViewModel to start the camera. As a best practice set it in OnAppearing() method override in your ContentPage.

  6. Listen to OnDetectionFinished event in Code-behind:

    <scanner:CameraView ...
                        OnDetectionFinished="CameraView_OnDetectionFinished"
                        .../>
    
    private void CameraView_OnDetectionFinished(object sender, OnDetectionFinishedEventArg e)
    {
        if (e.Length > 0)
            ...
    }
    

    or bind OnDetectionFinishedCommand property to a Command in your ViewModel:

    <scanner:CameraView ...
                        OnDetectionFinishedCommand="{Binding DetectionFinishedCommand}"
                        .../>
    
    public ICommand DetectionFinishedCommand { get; set; }
    ...
    DetectionFinishedCommand = new Command<BarcodeResult[]>(BarcodeResult[] result) =>
    {
        if (result.Length > 0)
            ...
    }
    
  7. As a best practice set the CameraEnabled property to false in OnDisappearing() method override in your ContentPage.

  8. From version 1.2.2 automatic disposing of CameraView is disabled! If a page gets regullary disposed, to prevent memory leaks add a listener to Unloaded event on your ContentPage.

    This mainly applies to a page registered as "details page" using Routing.RegisterRoute() method! Do not do this for pages registered in AppShell.xaml <ShellContent .../>, Shell Tabs or Flyout, or you will get a error when navigating back to the page!

    For example:

    <ContentPage ...
                 Unloaded="ContentPage_Unloaded"
                 ...>
    
        <scanner:CameraView x:Name="BarcodeView"
                            .../>
    
    private void ContentPage_Unloaded(object sender, EventArgs e)
    {
        BarcodeView.Handler?.DisconnectHandler();
    }
    
  9. From version 1.5.0 set the CaptureNextFrame property to true to capture next frame from the camera feed as a PlatformImage. Listen to OnImageCaptured event or bind to OnImageCapturedCommand 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 captured CaptureNextFrame property is automaticly set to false to prevent memory leaks. Example can be found in ScanTab.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 Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-android34.0 is compatible.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-ios17.2 is compatible.  net8.0-maccatalyst was computed.  net8.0-maccatalyst17.2 is compatible.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.1 321 11/25/2024
2.0.1 455 11/19/2024
2.0.0 247 11/18/2024
1.7.1 294 11/25/2024
1.6.0 1,743 11/11/2024
1.5.9 3,853 10/19/2024
1.5.8 4,221 10/1/2024
1.5.7 26,301 7/11/2024
1.5.6 9,157 6/19/2024
1.5.5 1,239 6/12/2024
1.5.3 3,123 5/24/2024
1.5.2 1,421 5/17/2024
1.5.0 12,294 4/20/2024
1.4.3 1,246 4/11/2024
1.4.2 1,408 4/4/2024
1.4.1 1,705 3/22/2024
1.4.0 576 3/17/2024
1.3.1 3,033 3/13/2024
1.3.0 152 3/13/2024
1.2.5 687 3/8/2024
1.2.4 6,154 1/24/2024
1.2.3 1,306 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 294 11/16/2023
0.9.3 5,099 4/19/2023
0.9.1 261 3/31/2023