Код: Выделить всё
MediaPicker.Default.CapturePhotoAsync()
[*] camera.maui с Camera = "
[*] zxing.net.maui с cameralocation.rear
плагин. /> < /ul>
На всех них фронтальная камера открывается по умолчанию, и нет очевидной настройки или переопределения, чтобы выбрать заднюю камеру. Даже установка предпочтений камеры (например, Cameradevice = Bult ) не имеет эффекта, особенно на Android.
Код: Выделить всё
using System;
using System.IO;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Storage; // MediaPicker
using Plugin.Maui.OCR; // OcrPlugin
namespace RearCameraOCR;
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private async void OnCaptureClicked(object sender, EventArgs e)
{
try
{
if (!MediaPicker.Default.IsCaptureSupported)
{
await DisplayAlert("Error", "Camera not supported.", "OK");
return;
}
// Always opens the front camera instead of rear
var photoFile = await MediaPicker.Default.CapturePhotoAsync();
if (photoFile == null)
return;
using var stream = await photoFile.OpenReadAsync();
using var ms = new MemoryStream();
await stream.CopyToAsync(ms);
var bytes = ms.ToArray();
photoImage.Source = ImageSource.FromStream(() => new MemoryStream(bytes));
var ocrResult = await OcrPlugin.Default.RecognizeTextAsync(bytes);
var text = ocrResult.AllText;
resultLabel.Text = string.IsNullOrWhiteSpace(text)
? "No text detected."
: text;
}
catch (Exception ex)
{
await DisplayAlert("Error", ex.Message, "OK");
}
}
}
< /code>
< /code>
Question:[/b]
How can I force .NET MAUI (on Android and iOS) to always use the rear camera by default when capturing photos? Is this limitation inherent to MediaPicker
Подробнее здесь: https://stackoverflow.com/questions/797 ... i-zxing-oc