CameraScanner.Maui
Camera preview and barcode scanner for .NET MAUI apps
Install / Use
/learn @thomasgalliker/CameraScanner.MauiREADME
CameraScanner.Maui
This library offers camera preview and barcode scanning functionality for .NET MAUI apps using native platform APIs with Google ML Kit and Apple VisionKit.
Download and Install CameraScanner.Maui
This library is available on NuGet: https://www.nuget.org/packages/CameraScanner.Maui Use the following command to install CameraScanner.Maui using NuGet package manager console:
PM> Install-Package CameraScanner.Maui
You can use this library in any .NET MAUI project compatible to .NET 8 and higher.
App Setup
- This plugin provides an extension method for MauiAppBuilder
UseCameraScannerwhich ensure proper startup and initialization. Call this method within yourMauiProgramjust as demonstrated in the CameraDemoApp:var builder = MauiApp.CreateBuilder() .UseMauiApp<App>() .UseCameraScanner(); - Add camera permission for Android in your
AndroidManifest.xmlfile. Add the followinguses-permissionentry inside of themanifestnode:<uses-permission android:name="android.permission.CAMERA" /> - Add camera permission for iOS in your
Info.plistfile. Add the following permission inside of thedictnode:
Permission strings can also be localized on iOS using lproj-folders and InfoPlist.strings files. Read this if you're interested in this topic.<key>NSCameraUsageDescription</key> <string>Required to display camera preview and scan barcodes.</string>
Sample App
In the Samples folder of this repository, you will find the CameraDemoApp, which demonstrates the features of CameraScanner.Maui. To debug, clone the repository and run the sample app directly in your development environment.
You can also download the sample app from the Google Play Store and the App Store using the links below:
<a href="https://play.google.com/store/apps/details?id=ch.superdev.camerascanner"> <img src="https://raw.githubusercontent.com/thomasgalliker/CameraScanner.Maui/refs/heads/develop/Images/GooglePlay/en_badge_web_generic.png" height="44px" alt="Get it on Google Play" /> </a> <a href="https://apps.apple.com/ch/app/camera-scanner-sdk/id6752654209"> <img src="https://raw.githubusercontent.com/thomasgalliker/CameraScanner.Maui/refs/heads/develop/Images/AppStore/download-on-the-app-store.svg" height="44px" alt="Download on the App Store"> </a>API Usage
The following documentation guides you trough the most important use cases of this library. Not all aspects are covered. If you think there is something important missing here, feel free to open a new issue.
This documentation only demonstrates the use of CameraScanner.Maui within a XAML and MVVM based app. Of course, the code also runs in C# and code-behind UIs.
Use CameraView in XAML
In order to add the camera preview control CameraView to your xaml page, you need to add the xml namespace in the root of your xaml file:
xmlns:c="http://camerascanner.maui"
Then, you can add CameraView to your xaml UI. Set CameraEnabled="True" in order to start the camera preview.
<c:CameraView CameraEnabled="True" />
There are several bindable properties in CameraView in order to configure and control the camera preview.
Configure CameraView
| Property | Description |
|-----------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| AutoDisconnectHandler | Defines if the platform handler is automatically disconnected or if Handler.DisconnectHandler(); is called manually. Default: true for (automatically disconnected). This property only exists for apps with TFM net8.0. |
| VibrationOnDetected | Enables or disables vibration on successful barcode detection. Default: false |
| SoundOnDetected | Enables or disables sound on successful barcode detection. Default: false |
| SoundSource | The stream of the sound used to indicate a successful barcode detection. |
| SoundVolume | The volume of the sound played when acoustic barcode detection is enabled. |
| CameraEnabled | Enables or disables the camera preview. Default: false |
| PauseScanning | Pauses barcode scanning. |
| ForceInverted | Forces scanning of inverted barcodes. Reduces performance significantly. Android only. |
| PoolingInterval | Enables pooling of detections for better detection of multiple barcodes at once. Value in milliseconds. Default: 0 (disabled). |
| TorchOn | Enables or disables the torch. |
| TapToFocusEnabled | Disables or enables tap-to-focus. |
| CameraFacing | Select front or back facing camera. Default:
