Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/redth/zxing.net.maui
Barcode Scanning for MAUI?
https://github.com/redth/zxing.net.maui
Last synced: 8 days ago
JSON representation
Barcode Scanning for MAUI?
- Host: GitHub
- URL: https://github.com/redth/zxing.net.maui
- Owner: Redth
- License: mit
- Created: 2021-08-06T13:45:27.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-12T07:17:23.000Z (5 months ago)
- Last Synced: 2024-07-14T10:44:20.925Z (4 months ago)
- Language: C#
- Size: 167 KB
- Stars: 435
- Watchers: 33
- Forks: 146
- Open Issues: 116
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ZXing.Net.MAUI
The successor to ZXing.Net.Mobile: barcode scanning and generation for .NET MAUI applications
## Barcode Scanning
### Install ZXing.Net.MAUI
1. Install [ZXing.Net.Maui.Controls](https://www.nuget.org/packages/ZXing.Net.Maui.Controls) NuGet package on your .NET MAUI application
1. Make sure to initialize the plugin first in your `MauiProgram.cs`, see below
```csharp
// Add the using to the top
using ZXing.Net.Maui;
// ... other code
public static MauiApp Create()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp()
.UseBarcodeReader(); // Make sure to add this line
return builder.Build();
}
```Now we just need to add the right permissions to our app metadata. Find below how to do that for each platform.
#### Android
For Android go to your `AndroidManifest.xml` file (under the Platforms\Android folder) and add the following permissions inside of the `manifest` node:
```xml
```
#### iOS
For iOS go to your `info.plist` file (under the Platforms\iOS folder) and add the following permissions inside of the `dict` node:
```xml
NSCameraUsageDescription
This app uses barcode scanning to...
```Make sure that you enter a clear and valid reason for your app to access the camera. This description will be shown to the user.
#### Windows
Windows is not supported at this time for barcode scanning. You can however use the barcode generation. No extra permissions are required for that.
For more information on permissions, see the [Microsoft Docs](https://docs.microsoft.com/dotnet/maui/platform-integration/appmodel/permissions).
### Using ZXing.Net.Maui
If you're using the controls from XAML, make sure to add the right XML namespace in the root of your file, e.g: `xmlns:zxing="clr-namespace:ZXing.Net.Maui.Controls;assembly=ZXing.Net.MAUI.Controls"`
```xaml
```
Configure Reader options
```csharp
cameraBarcodeReaderView.Options = new BarcodeReaderOptions
{
Formats = BarcodeFormats.OneDimensional,
AutoRotate = true,
Multiple = true
};
```Toggle Torch
```csharp
cameraBarcodeReaderView.IsTorchOn = !cameraBarcodeReaderView.IsTorchOn;
```Flip between Rear/Front cameras
```csharp
cameraBarcodeReaderView.CameraLocation
= cameraBarcodeReaderView.CameraLocation == CameraLocation.Rear ? CameraLocation.Front : CameraLocation.Rear;
```Handle detected barcode(s)
```csharp
protected void BarcodesDetected(object sender, BarcodeDetectionEventArgs e)
{
foreach (var barcode in e.Results)
Console.WriteLine($"Barcodes: {barcode.Format} -> {barcode.Value}");
}
```## Barcode Generator View
```xaml```