Coder Social home page Coder Social logo

danielcodingpilot / barcodescanning.native.maui Goto Github PK

View Code? Open in Web Editor NEW

This project forked from afriscic/barcodescanning.native.maui

0.0 0.0 0.0 243 KB

Barcode scanning library for .NET MAUI

Home Page: https://www.nuget.org/packages/BarcodeScanning.Native.Maui

License: MIT License

C# 100.00%

barcodescanning.native.maui's Introduction

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.

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. Code-behind and MVVM compatibility,
  8. 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

    Edit info.plist file (under the Platforms\iOS 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 or bind OnDetectionFinishedCommand property to a Command in your ViewModel.

  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();
    }

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

1D: Codabar, Code 39, Code 93, Code 128, EAN-8, EAN-13, GS1 DataBar, ITF, 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 and macOS support

Windows and macOS are currently unsupported, but support can be added in the future. Vision framework is compatible with macOS so this implementation wouldn't be difficult. For Windows, barcode detection could be supported through Zxing.Net project.

barcodescanning.native.maui's People

Contributors

afriscic avatar opterjohan-hallberg avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.