Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/afriscic/BarcodeScanning.Native.Maui
Barcode scanning library for .NET MAUI
https://github.com/afriscic/BarcodeScanning.Native.Maui
android barcode barcode-reader barcode-scanner dotnet ios macos maui
Last synced: 3 months ago
JSON representation
Barcode scanning library for .NET MAUI
- Host: GitHub
- URL: https://github.com/afriscic/BarcodeScanning.Native.Maui
- Owner: afriscic
- License: mit
- Created: 2023-03-31T08:03:13.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-05-23T06:06:24.000Z (6 months ago)
- Last Synced: 2024-05-23T07:25:06.799Z (6 months ago)
- Topics: android, barcode, barcode-reader, barcode-scanner, dotnet, ios, macos, maui
- Language: C#
- Homepage: https://www.nuget.org/packages/BarcodeScanning.Native.Maui
- Size: 370 KB
- Stars: 101
- Watchers: 6
- Forks: 24
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
- awesome-dotnet-maui - BarcodeScanning.Native.Maui - square)](https://github.com/afriscic/BarcodeScanning.Native.Maui/stargazers)|[![GitHub last-commit](https://img.shields.io/github/last-commit/afriscic/BarcodeScanning.Native.Maui?style=flat-square)](https://github.com/afriscic/BarcodeScanning.Native.Maui/commits) (Plugins)
README
# BarcodeScanning.Native.Maui
Barcode scanning library based on native platform APIs for barcode detection:
1. [Google ML Kit](https://developers.google.com/ml-kit)
2. [Apple Vision framework](https://developer.apple.com/documentation/vision)This library was inspired by existing MAUI barcode scanning libraries: [BarcodeScanner.Mobile](https://github.com/JimmyPun610/BarcodeScanner.Mobile) & [Zxing.Net.MAUI](https://github.com/Redth/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](https://www.nuget.org/packages/BarcodeScanning.Native.Maui),
2. Initialize the plugin in your `MauiProgram.cs`:
```csharp
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:
```xml
```
#### iOS/macOS
Edit `info.plist` file (under the Platforms\iOS or Platforms\MacCatalyst folder) and add the following permissions inside of the `dict` node:
```xml
NSCameraUsageDescription
Enable camera for barcode scanning.
```
And ask for permission from user in your code:
```csharp
await Methods.AskForRequiredPermissionAsync();
```
4. In XAML, add correct namespace, for example:
```xaml
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:
```xaml
```
```csharp
private void CameraView_OnDetectionFinished(object sender, OnDetectionFinishedEventArg e)
{
if (e.BarcodeResults.Length > 0)
...
}
```
or bind `OnDetectionFinishedCommand` property to a Command in your ViewModel:
```xaml
```
```csharp
public ICommand DetectionFinishedCommand { get; set; }
...
DetectionFinishedCommand = new Command(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` ``, Shell Tabs or Flyout, or you will get a error when navigating back to the page!**
For example:
```xaml
```
```csharp
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](https://github.com/afriscic/BarcodeScanning.Native.Maui/blob/master/BarcodeScanning.Native.Maui/CameraView.cs) source file.## TODO Windows support
Windows is currently unsupported, but support can be added in the future through [Zxing.Net](https://github.com/micjahn/ZXing.Net) project.