Browse Source

Disable Camera option on ProcessAndRenderPage on Android when there are 0 cameras.

pull/768/merge
Canming Huang 2 months ago
parent
commit
67cfacf7f7
  1. 44
      Emgu.CV.Runtime/Maui/UI/ButtonTextImagePage.cs
  2. 9
      Emgu.CV.Runtime/Maui/UI/ProcessAndRenderPage.cs

44
Emgu.CV.Runtime/Maui/UI/ButtonTextImagePage.cs

@ -247,25 +247,38 @@ namespace Emgu.CV.Platform.Maui.UI
{
Mat[] mats = new Mat[imageNames.Length];
SetMessage("Checking if camera option is available, please wait...");
//Run it once in case it need to check if camera is available, which could take a long time to run
await Task.Run(() => { bool cameraOption = this.HasCameraOption; });
SetMessage(null);
bool captureSupported;
if (Microsoft.Maui.Devices.DeviceInfo.Platform == DevicePlatform.WinUI
|| Microsoft.Maui.Devices.DeviceInfo.Platform == DevicePlatform.macOS)
{
//Pick image from camera is not implemented on WPF.
captureSupported = false;
}
else
{
captureSupported = MediaPicker.IsCaptureSupported;
if (Microsoft.Maui.Devices.DeviceInfo.Platform == DevicePlatform.Android)
{
//Overwrite MediaPicker if there is no camera on this Android device.
if (!this.HasCameraOption)
{
captureSupported = false;
}
}
}
for (int i = 0; i < mats.Length; i++)
{
String pickImgString = "Use Image from";
if (labels != null && labels.Length > i)
pickImgString = labels[i];
bool captureSupported;
if (Microsoft.Maui.Devices.DeviceInfo.Platform == DevicePlatform.WinUI
|| Microsoft.Maui.Devices.DeviceInfo.Platform == DevicePlatform.macOS)
{
//Pick image from camera is not implemented on WPF.
captureSupported = false;
}
else
{
captureSupported = MediaPicker.IsCaptureSupported;
}
String action;
List<String> options = new List<string>();
options.Add("Default");
@ -275,11 +288,6 @@ namespace Emgu.CV.Platform.Maui.UI
if (captureSupported)
options.Add("Photo from Camera");
SetMessage("Checking if camera option is available, please wait...");
//Run it once in case it need to check if camera is available, which could take a long time to run
await Task.Run(() => { bool cameraOption = this.HasCameraOption; });
SetMessage(null);
if (this.HasCameraOption)
{
if (Microsoft.Maui.Devices.DeviceInfo.Platform == DevicePlatform.Android)

9
Emgu.CV.Runtime/Maui/UI/ProcessAndRenderPage.cs

@ -87,9 +87,14 @@ namespace Emgu.CV.Platform.Maui.UI
|| Microsoft.Maui.Devices.DeviceInfo.Platform == DevicePlatform.MacCatalyst
|| Microsoft.Maui.Devices.DeviceInfo.Platform == DevicePlatform.WinUI))
{
#if __ANDROID__
#if __ANDROID__
if (CameraBackend == AndroidCameraBackend.AndroidCamera2)
return true;
{
var context = Android.App.Application.Context;
var cameraManager = (Android.Hardware.Camera2.CameraManager) context.GetSystemService(Android.Content.Context.CameraService);
var cameraCount = cameraManager?.GetCameraIdList()?.Length;
return cameraCount > 0;
}
#endif
if (CvInvoke.Backends.Length > 0)

Loading…
Cancel
Save