Camera.MAUI 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Camera.MAUI --version 1.0.0                
NuGet\Install-Package Camera.MAUI -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Camera.MAUI" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Camera.MAUI --version 1.0.0                
#r "nuget: Camera.MAUI, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Camera.MAUI as a Cake Addin
#addin nuget:?package=Camera.MAUI&version=1.0.0

// Install Camera.MAUI as a Cake Tool
#tool nuget:?package=Camera.MAUI&version=1.0.0                

Camera.MAUI

A Camera View control and a Barcode Endode/Decode control (based on ZXing.Net) for .NET MAUI applications.

CameraView

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

Install and configure CameraView

  1. Download and Install Camera.MAUI NuGet package on your application.

  2. 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();
    }
    
  3. Add camera permissions to your application:

Android

In your AndroidManifest.xml file (Platforms\Android) add the following permission:

<uses-permission android:name="android.permission.CAMERA" />
iOS/MacCatalyst

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.

Windows

In your Package.appxmanifest file (Platforms\Windows) go to Capabilities and mark Web Camera.

For more information on permissions, see the Microsoft Docs.

Using CameraView

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

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

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

BarcodeImage

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 Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-android33.0 is compatible.  net7.0-ios was computed.  net7.0-ios16.1 is compatible.  net7.0-maccatalyst was computed.  net7.0-maccatalyst16.1 is compatible.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net7.0-windows10.0.19041 is compatible.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 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.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.5.1 35,364 2/29/2024
1.5.0 2,236 2/29/2024
1.4.4 105,953 6/9/2023
1.4.3 2,455 5/24/2023
1.4.2 718 5/19/2023
1.4.1 1,284 5/17/2023
1.4.0 1,016 5/12/2023
1.3.5 3,110 4/15/2023
1.3.4 773 4/13/2023
1.3.3 206 4/13/2023
1.3.2 171 4/13/2023
1.3.1 303 4/11/2023
1.3.0 384 4/9/2023
1.2.1 4,044 3/30/2023
1.2.0 256 3/30/2023
1.1.0 502 3/10/2023
1.0.0 421 3/9/2023