![]() |
VOOZH | about |
dotnet add package Camera.MAUI --version 1.2.0
NuGet\Install-Package Camera.MAUI -Version 1.2.0
<PackageReference Include="Camera.MAUI" Version="1.2.0" />
<PackageVersion Include="Camera.MAUI" Version="1.2.0" />Directory.Packages.props
<PackageReference Include="Camera.MAUI" />Project file
paket add Camera.MAUI --version 1.2.0
#r "nuget: Camera.MAUI, 1.2.0"
#:package Camera.MAUI@1.2.0
#addin nuget:?package=Camera.MAUI&version=1.2.0Install as a Cake Addin
#tool nuget:?package=Camera.MAUI&version=1.2.0Install as a Cake Tool
A Camera View control and a Barcode Endode/Decode control (based on ZXing.Net) for .NET MAUI applications.
A ContetView control for camera management with the next properties:
| Android | iOS/Mac | Windows | |
|---|---|---|---|
| Preview | ✅ | ✅ | ✅ |
| Mirror preview | ✅ | ✅ | ✅ |
| Flash | ✅ | ✅ | ✅ |
| Torch | ✅ | ✅ | ✅ |
| Zoom | ✅ | ✅ | ✅ |
| Take snapshot | ✅ | ✅ | ✅ |
| Save snapshot | ✅ | ✅ | ✅ |
| Barcode detection/decode | ✅ | ✅ | ✅ |
Download and Install Camera.MAUI NuGet package on your application.
Initialize the plugin in your MauiProgram.cs:
// Add the using to the top
using Camera.MAUI;
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiCameraView(); // Add the use of the plugging
return builder.Build();
}
Add camera permissions to your application:
In your AndroidManifest.xml file (Platforms\Android) add the following permission:
<uses-permission android:name="android.permission.CAMERA" />
In your info.plist file (Platforms\iOS / Platforms\MacCatalyst) add the following permission:
<key>NSCameraUsageDescription</key>
<string>This app uses camera for...</string>
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.
In your Package.appxmanifest file (Platforms\Windows) go to Capabilities and mark Web Camera.
For more information on permissions, see the Microsoft Docs.
In XAML, make sure to add the right XML namespace:
xmlns:cv="xmlns:cv="clr-namespace:Camera.MAUI;assembly=Camera.MAUI"
Use the control:
<cv:CameraView x:Name="cameraView" WidthRequest="300" HeightRequest="200"/>
Configure the events:
cameraView.CamerasLoaded += CameraView_CamerasLoaded;
cameraView.BarcodeDetected += CameraView_BarcodeDetected;
Configure the camera to use:
private void CameraView_CamerasLoaded(object sender, EventArgs e)
{
if (cameraView.Cameras.Count > 0)
{
cameraView.Camera = cameraView.Cameras.First();
MainThread.BeginInvokeOnMainThread(async () =>
{
if (await cameraView.StartCameraAsync() == CameraResult.Success)
{
controlButton.Text = "Stop";
playing = true;
}
});
}
}
CameraInfo type (Camera Property): CameraInfo has the next properties:
public string Name
public string DeviceId
public CameraPosition Position
public bool HasFlashUnit
public float MinZoomFactor
public float MaxZoomFactor
Start camera playback:
if (await cameraView.StartCameraAsync() == CameraResult.Success)
{
playing = true;
}
Stop camera playback:
if (await cameraView.StopCameraAsync() == CameraResult.Success)
{
playing = false;
}
Set Flash mode
cameraView.FlashMode = FlashMode.Auto;
Toggle Torch
cameraView.TorchEnabled = !cameraView.TorchEnabled;
Set mirrored mode
cameraView.MirroredImage = true;
Set zoom factor
if (cameraView.MaxZoomFactor >= 2.5f)
cameraView.ZoomFactor = 2.5f;
Get a snapshot from the playback
ImageSource imageSource = cameraView.GetSnapShot(ImageFormat.PNG);
Get a snapshot MVVM: The control has several binding properties for take an snapshot:
/// Sets how often the SnapShot property is updated in seconds.
/// Default 0: no snapshots are taken
/// WARNING! A low frequency directly impacts over control performance and memory usage (with AutoSnapShotAsImageSource = true)
/// </summary>
public float AutoSnapShotSeconds
/// Sets the snaphost image format
public ImageFormat AutoSnapShotFormat
/// Refreshes according to the frequency set in the AutoSnapShotSeconds property (if AutoSnapShotAsImageSource is set to true) or when GetSnapShot is called or TakeAutoSnapShot is set to true
public ImageSource SnapShot
/// Refreshes according to the frequency set in the AutoSnapShotSeconds property or when GetSnapShot is called.
/// WARNING. Each time a snapshot is made, the previous stream is disposed.
public Stream SnapShotStream
/// Change from false to true refresh SnapShot property
public bool TakeAutoSnapShot
/// If true SnapShot property is refreshed according to the frequency set in the AutoSnapShotSeconds property
public bool AutoSnapShotAsImageSource
Enable and Handle barcodes detection:
cameraView.BarcodeDetected += CameraView_BarcodeDetected;
cameraView.BarCodeOptions = new ZXingHelper.BarcodeDecodeOptions
{
AutoRotate = true,
PossibleFormats = { ZXing.BarcodeFormat.QR_CODE },
ReadMultipleCodes = false,
TryHarder = true,
TryInverted = true
};
cameraView.BarCodeDetectionFrameRate = 10;
cameraView.BarCodeDetectionEnabled = true;
private void CameraView_BarcodeDetected(object sender, ZXingHelper.BarcodeEventArgs args)
{
Debug.WriteLine("BarcodeText=" + args.Result[0].Text);
}
A ContentView control for generate codebars images.
In XAML, make sure to add the right XML namespace:
xmlns:cv="xmlns:cv="clr-namespace:Camera.MAUI;assembly=Camera.MAUI"
Use the control and its bindable properties:
<cv:BarcodeImage x:Name="barcodeImage" Aspect="AspectFit"
WidthRequest="400" HeightRequest="400"
BarcodeWidth="200" BarcodeHeight="200" BarcodeMargin="5"
BarcodeBackground="White" BarcodeForeground="Blue"
BarcodeFormat="QR_CODE" />
Set the barcode property to generate the image:
barcodeImage.Barcode = "https://github.com/hjam40/Camera.MAUI";
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net7.0 net7.0 is compatible. net7.0-android net7.0-android was computed. net7.0-android33.0 net7.0-android33.0 is compatible. net7.0-ios net7.0-ios was computed. net7.0-ios16.1 net7.0-ios16.1 is compatible. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-maccatalyst16.1 net7.0-maccatalyst16.1 is compatible. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net7.0-windows10.0.19041 net7.0-windows10.0.19041 is compatible. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 5 NuGet packages that depend on Camera.MAUI:
| Package | Downloads |
|---|---|
|
Camera.MAUI.ZXing
A Barcode Endode/Decode control (based on ZXing.Net) for use with Camera.MAUI in .NET MAUI applications. |
|
|
VertiGIS.Mobile
Create VertiGIS Mobile apps for Android, iOS, and UWP. Extend your apps with custom components, operations and services. |
|
|
Cyber.FrameworkNet8
Phiên bản CyberPlus phát triển trên nền tảng .Net Maui |
|
|
Cyber.FrameworkNet8_FutaHaSon
Phiên bản FTHS khách hàng phát triển trên nền tảng .Net Maui |
|
|
Cephei.Libraries.Maui.Camera
MAUI library for Camera usage (uses Camera.Maui). |
Showing the top 3 popular GitHub repositories that depend on Camera.MAUI:
| Repository | Stars |
|---|---|
|
bitwarden/mobile
Retired Bitwarden mobile app for iOS and Android (MAUI/Xamarin).
|
|
|
exendahal/ecommerce_maui
E-commerce design using .NET MAUI (.NET 8)
|
|
|
zhulige/xiaozhi-sharp
C# 版本的小智SDK & Client,支持Windows、Linux、Mac、Android、IOS 等。
|
| Version | Downloads | Last Updated |
|---|---|---|
| 1.5.1 | 369,464 | 2/29/2024 |
| 1.5.0 | 100,226 | 2/29/2024 |
| 1.4.4 | 207,876 | 6/9/2023 |
| 1.4.3 | 2,885 | 5/24/2023 |
| 1.4.2 | 1,021 | 5/19/2023 |
| 1.4.1 | 2,055 | 5/17/2023 |
| 1.4.0 | 1,617 | 5/12/2023 |
| 1.3.5 | 4,342 | 4/15/2023 |
| 1.3.4 | 1,012 | 4/13/2023 |
| 1.3.3 | 516 | 4/13/2023 |
| 1.3.2 | 389 | 4/13/2023 |
| 1.3.1 | 579 | 4/11/2023 |
| 1.3.0 | 1,170 | 4/9/2023 |
| 1.2.1 | 10,790 | 3/30/2023 |
| 1.2.0 | 520 | 3/30/2023 |
| 1.1.0 | 772 | 3/10/2023 |
| 1.0.0 | 780 | 3/9/2023 |
Added MVVM snapshot properties