diff --git a/Emgu.CV.Runtime/Maui/UI/ButtonTextImagePage.cs b/Emgu.CV.Runtime/Maui/UI/ButtonTextImagePage.cs index 55c64b1e3..fafa78c07 100644 --- a/Emgu.CV.Runtime/Maui/UI/ButtonTextImagePage.cs +++ b/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 options = new List(); 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) diff --git a/Emgu.CV.Runtime/Maui/UI/ProcessAndRenderPage.cs b/Emgu.CV.Runtime/Maui/UI/ProcessAndRenderPage.cs index f5ad7c92c..80c1727eb 100644 --- a/Emgu.CV.Runtime/Maui/UI/ProcessAndRenderPage.cs +++ b/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)