I am constructing a cross-platform .NET MAUI app that makes use of the digital camera to take a photograph and run OCR (by way of Amazon Rekognition or Plugin.Maui.OCR). Whatever the platform (Android or iOS), each API I’ve tried at all times opens the entrance/selfie digital camera, although I need the rear digital camera by default.
I’ve tried the next:
MediaPicker.Default.CapturePhotoAsync()
- Digital camera.MAUI with
Digital camera = "Rear"
- ZXing.Web.MAUI with
CameraLocation.Rear
- Plugin.Maui.OCR seize integration
On all of them, the entrance digital camera opens by default, and there’s no apparent setting or override to pick out the rear digital camera. Even setting digital camera preferences (e.g., CameraDevice = Rear
) has no impact—particularly on Android.
This simplified instance makes use of MediaPicker + Plugin.Maui.OCR, however the difficulty is similar with the others:
utilizing System;
utilizing System.IO;
utilizing Microsoft.Maui.Controls;
utilizing Microsoft.Maui.Storage; // MediaPicker
utilizing Plugin.Maui.OCR; // OcrPlugin
namespace RearCameraOCR;
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
personal async void OnCaptureClicked(object sender, EventArgs e)
{
strive
{
if (!MediaPicker.Default.IsCaptureSupported)
{
await DisplayAlert("Error", "Digital camera not supported.", "OK");
return;
}
// At all times opens the entrance digital camera as an alternative of rear
var photoFile = await MediaPicker.Default.CapturePhotoAsync();
if (photoFile == null)
return;
utilizing var stream = await photoFile.OpenReadAsync();
utilizing var ms = new MemoryStream();
await stream.CopyToAsync(ms);
var bytes = ms.ToArray();
photoImage.Supply = ImageSource.FromStream(() => new MemoryStream(bytes));
var ocrResult = await OcrPlugin.Default.RecognizeTextAsync(bytes);
var textual content = ocrResult.AllText;
resultLabel.Textual content = string.IsNullOrWhiteSpace(textual content)
? "No textual content detected."
: textual content;
}
catch (Exception ex)
{
await DisplayAlert("Error", ex.Message, "OK");
}
}
}
Query:
How can I power .NET MAUI (on Android and iOS) to at all times use the rear digital camera by default when capturing images? Is that this limitation inherent to MediaPicker
(i.e., it at all times makes use of the system UI), or is there a workaround/API that enables deciding on the rear digital camera?