/// <summary>
        /// Helper method to obtain a device Id that supports a Video Profile.
        /// If no Video Profile is found we return empty string indicating that there isn't a device on
        /// the desired panel with a supported Video Profile.
        /// </summary>
        /// <param name="panel">Contains Device Enumeration information regarding camera panel we are looking for</param>
        /// <returns>Device Information Id string</returns>
        public async Task <string> GetVideoProfileSupportedDeviceIdAsync(Windows.Devices.Enumeration.Panel panel)
        {
            string deviceId = string.Empty;

            // Find all video capture devices
            await LogStatusToOutputBox("Looking for all video capture devices");

            DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            await LogStatusToOutputBox(string.Format(CultureInfo.InvariantCulture, "Number of video capture devices found: {0}", devices.Count.ToString()));

            // Loop through devices looking for device that supports Video Profile
            foreach (var device in devices)
            {
                // Check if the device on the requested panel supports Video Profile
                if (MediaCapture.IsVideoProfileSupported(device.Id) && device.EnclosureLocation.Panel == panel)
                {
                    // We've located a device that supports Video Profiles on expected panel
                    deviceId = device.Id;
                    break;
                }
            }

            return(deviceId);
        }
Exemple #2
0
        /// <summary>
        /// Initialze MediaCapture
        /// </summary>
        /// <param name="panel"></param>
        /// <returns></returns>
        public async Task InitializeCapture(Windows.Devices.Enumeration.Panel panel = Windows.Devices.Enumeration.Panel.Back)
        {
            mediaCapture      = new MediaCapture();
            this.currentPanel = panel;
            MediaCaptureInitializationSettings setting = await InitializeSettings(panel);

            if (setting != null)
            {
                await mediaCapture.InitializeAsync(setting);
            }
            else
            {
                await mediaCapture.InitializeAsync();
            }
            var resolutions = this.mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo);

            if (resolutions.Count >= 1)
            {
                var hires = resolutions.OrderByDescending(item => ((VideoEncodingProperties)item).Width).First();
                await mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, hires);
            }
            if (!this.isExternalCamera)
            {
                var previewRotation = (this.currentPanel == Windows.Devices.Enumeration.Panel.Back) ? VideoRotation.Clockwise90Degrees : VideoRotation.Clockwise270Degrees;
                try
                {
                    mediaCapture.SetPreviewRotation(previewRotation);
                    mediaCapture.SetRecordRotation(previewRotation);
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
            }
        }
        private static async Task <DeviceInformation> GetCameraID(Panel camera)
        {
            var deviceID = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture))
                           .FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == camera);

            return(deviceID);
        }
Exemple #4
0
        private async Task <DeviceInformation> FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel desiredPanel)
        {
            // Get available devices for capturing pictures
            var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            m_hasFrontAndBackCamera = allVideoDevices.Any(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front) &&
                                      allVideoDevices.Any(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);

            // Get the desired camera by panel
            DeviceInformation desiredDevice = allVideoDevices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == desiredPanel);

            // If there is no device mounted on the desired panel, use the first device found
            desiredDevice = desiredDevice ?? allVideoDevices.FirstOrDefault();
            if (desiredDevice != null)
            {
                m_desiredCameraPanel = desiredPanel;
                m_mirroringPreview   = desiredPanel == Windows.Devices.Enumeration.Panel.Front;
                if (desiredDevice.EnclosureLocation == null || desiredDevice.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Unknown)
                {
                    // No information on the location of the camera, assume it's an external camera, not integrated on the device
                    m_externalCamera = true;
                }
                else
                {
                    m_externalCamera = false;
                }
            }

            return(desiredDevice);
        }
Exemple #5
0
        public MainViewModel()
        {
            PreviewVideoElementLoadedCommand = new DelegateCommand <FrameworkElement>(OnFrameworkElementLoaded);
            m_configurationPropertySet       = new PropertySet();

            Application.Current.Suspending += OnApplicationSuspending;
            Application.Current.Resuming   += OnApplicationResuming;
            SystemMediaTransportControls.GetForCurrentView().PropertyChanged += OnMediaPropertyChanged;

            StartStopRecordCommand = new DelegateCommand(OnStartStopRecord, OnCanExecutePlayRecord);
            CaptureCommand         = new DelegateCommand(OnCaptureImage, CanExecuteCaptureImage);
            ToggleCameraCommand    = new DelegateCommand(OnToggleCamera, CanExecuteToggleCamera);

            Effects            = CreateEditableEffects();
            NonEditableEffects = CreateNonEditableEffects();

            m_imageConsumerEffect = m_contrastEffect;
            m_imageProviderEffect = m_brightnessEffect;

            m_desiredCameraPanel = Windows.Devices.Enumeration.Panel.Back;

            UpdateConfiguration();

            CurrentState  = "Normal";
            CurrentEditor = Effects.FirstOrDefault();

            IsRecordingEnabled  = true;
            m_externalCamera    = false;
            m_isToggelingCamera = false;
        }
        private static async Task <DeviceInformation> FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel desiredPanel)
        {
            var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            var desiredDevice = allVideoDevices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == desiredPanel);

            return(desiredDevice ?? allVideoDevices.FirstOrDefault());
        }
        private async Task <DeviceInformation> GetCameraDeviceInformationAsync(Windows.Devices.Enumeration.Panel panel)
        {
            var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            var desiredDevices = allVideoDevices.FirstOrDefault(
                x => x.IsEnabled && x.EnclosureLocation != null && x.EnclosureLocation.Panel == panel);

            return(desiredDevices);
        }
                public async Task <DeviceInformation> FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel desiredPanel)
                {
                    // Get available devices for capturing pictures
                    var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

                    // Get the desired camera by panel
                    DeviceInformation desiredDevice = allVideoDevices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == desiredPanel);

                    // If there is no device mounted on the desired panel, return the first device found
                    return(desiredDevice ?? allVideoDevices.FirstOrDefault());
                }
        /// <summary>
        /// Queries the available video capture devices to try and find one mounted on the desired panel
        /// </summary>
        /// <param name="desiredPanel">The panel on the device that the desired camera is mounted on</param>
        /// <returns>A DeviceInformation instance with a reference to the camera mounted on the desired panel if available,
        ///          any other camera if not, or null if no camera is available.</returns>
        private static async Task<DeviceInformation> FindCameraDeviceByPanelAsync(Panel desiredPanel)
        {
            // Get available devices for capturing pictures
            var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            // Get the desired camera by panel
            DeviceInformation desiredDevice = allVideoDevices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == desiredPanel);

            // If there is no device mounted on the desired panel, return the first device found
            return desiredDevice ?? allVideoDevices.FirstOrDefault();
        }
        private static async Task <DeviceInformation> GetCameraDeviceInfoAsync(Windows.Devices.Enumeration.Panel desiredPanel)
        {
            DeviceInformation device = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture))
                                       .FirstOrDefault(d => d.EnclosureLocation != null && d.EnclosureLocation.Panel == desiredPanel);

            if (device == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "No suitable devices found for the camera of type {0}.", desiredPanel));
            }
            return(device);
        }
        /// <summary>
        /// 获取相机装置
        /// </summary>
        /// <param name="back"></param>
        /// <returns></returns>
        private async Task <DeviceInformation> FindCamerDeviceByPanel(Windows.Devices.Enumeration.Panel back)
        {
            //获取所有视频可以捕获的设备
            var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            //得到计算机背部的设备
            DeviceInformation desiredDevice = allVideoDevices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == back);

            //如果没有计算机背部的设备,则返回第一个发现的设备,比如外部摄像机,或者其他
            return(desiredDevice ?? allVideoDevices.FirstOrDefault());
        }
Exemple #12
0
        // Queries the available video capture devices to try and find one mounted on the desired panel.
        // DesiredPanel is the panel on the device that the desired camera is mounted on.
        private static async Task <DeviceInformation> FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel desiredPanel)
        {
            // Get available devices for capturing pictures
            var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            // Get the desired camera by panel
            DeviceInformation desiredDevice = allVideoDevices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == desiredPanel);

            // If there is no device mounted on the desired panel, return the first device found
            // If whatever is to the left is not null, use that, otherwise use what's to the right.
            // Ternary style
            return(desiredDevice ?? allVideoDevices.FirstOrDefault());
        }
        private CameraPanel ConvertDevicePanelToCameraPanel(Windows.Devices.Enumeration.Panel panel)
        {
            switch (panel)
            {
            case Windows.Devices.Enumeration.Panel.Front:
                return(CameraPanel.Front);

            case Windows.Devices.Enumeration.Panel.Back:
            case Windows.Devices.Enumeration.Panel.Unknown:
            default:
                return(CameraPanel.Back);
            }
        }
Exemple #14
0
        private static async Task <DeviceInformation> GetCameraID(Windows.Devices.Enumeration.Panel desired)
        {
            DeviceInformation deviceID = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture))
                                         .FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == desired);

            if (deviceID != null)
            {
                return(deviceID);
            }
            else
            {
                throw new Exception(string.Format("Camera of type {0} doesn't exist.", desired));
            }
        }
Exemple #15
0
        public async Task UpdatePanelAsync(Windows.Devices.Enumeration.Panel panel)
        {
            if (panel == _panel)
            {
                return;
            }

            _panel = panel;
            if (IsInitialized)
            {
                await CleanupMediaCaptureAsync();
                await InitializeAsync().ConfigureAwait(false);
            }
        }
Exemple #16
0
        /// <summary>
        /// Queries the available video capture devices to try and find one mounted on the desired panel.
        /// </summary>
        /// <param name="desiredPanel">The panel on the device that the desired camera is mounted on.</param>
        /// <returns>A DeviceInformation instance with a reference to the camera mounted on the desired panel if available,
        ///          any other camera if not, or null if no camera is available.</returns>
        private static async Task <DeviceInformation> FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel desiredPanel)
        {
            // Get available devices for capturing pictures.6
            var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            Debug.WriteLine(allVideoDevices.Count);

            // Get the desired camera by panel.

            //DeviceInformation desiredDevice = allVideoDevices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == desiredPanel);
            DeviceInformation desiredDevice = allVideoDevices.ElementAt(allVideoDevices.Count > 2?2:0);

            // If there is no device mounted on the desired panel, return the first device found.
            return(desiredDevice ?? allVideoDevices.FirstOrDefault());
        }
Exemple #17
0
        private static async Task <DeviceInformation> FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel desiredPanel)
        {
            // Get available devices for capturing pictures
            var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            // Get the desired camera by panel
            DeviceInformation desiredDevice = allVideoDevices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == desiredPanel);

            // If there is no device mounted on the desired panel, return the first device found
            if (desiredDevice == null)
            {
                Debug.WriteLine("No device was found on the desired panel. First device found was returned.");
                return(allVideoDevices.FirstOrDefault());
            }
            return(desiredDevice);
        }
Exemple #18
0
        private async void OnToggleCamera()
        {
            m_isToggelingCamera = true;
            UpdateButtonState();
            await StopPreviewAsync();

            if (m_desiredCameraPanel == Windows.Devices.Enumeration.Panel.Back)
            {
                m_desiredCameraPanel = Windows.Devices.Enumeration.Panel.Front;
            }
            else
            {
                m_desiredCameraPanel = Windows.Devices.Enumeration.Panel.Back;
            }
            await StartPreviewAsync();

            m_isToggelingCamera = false;
            UpdateButtonState();
        }
Exemple #19
0
        public async Task <string> GetVideoProfileSupportedDeviceIdAsync(Windows.Devices.Enumeration.Panel panel)
        {
            string deviceId = string.Empty;

            // すべてのビデオキャプチャデバイスを見つける
            DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            foreach (var device in devices)
            {
                // MoverioCameraIdがわからない場合は、下のコードのコメントを外して調べる
                // ShowMessageToUser(device.Id);
                if (device.Id.Contains(MoverioCameraId))
                {
                    deviceId = device.Id;
                    break;
                }
            }

            return(deviceId);
        }
Exemple #20
0
        /// <summary>
        /// Get MediaCaptureInitializationSettings
        /// </summary>
        /// <param name="panel"></param>
        /// <returns></returns>
        private async Task <MediaCaptureInitializationSettings> InitializeSettings(Windows.Devices.Enumeration.Panel panel)
        {
            MediaCaptureInitializationSettings setting = null;
            DeviceInformation deviceFront = null;
            var deviceCollection          = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            if (deviceCollection == null || deviceCollection.Count == 0)
            {
                return(null);
            }
            if (deviceCollection.Count >= 2)
            {
                this.deviceInfo = deviceCollection.FirstOrDefault(d => d.EnclosureLocation.Panel == panel);
                deviceFront     = deviceCollection.FirstOrDefault(d => d.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front);
            }
            if (deviceFront != null)
            {
                this.isSupportFront = true;
            }
            else
            {
                this.isSupportFront = false;
            }
            if (this.deviceInfo != null)
            {
                setting = new MediaCaptureInitializationSettings();
                setting.AudioDeviceId = "";
                setting.VideoDeviceId = this.deviceInfo.Id;
            }
            else if (deviceCollection.Count == 1 && deviceCollection[0].EnclosureLocation == null)
            {
                setting = new MediaCaptureInitializationSettings();
                setting.AudioDeviceId = "";
                setting.VideoDeviceId = deviceCollection[0].Id;
                this.isExternalCamera = true;
            }
            return(setting);
        }
Exemple #21
0
        /// <summary>
        /// Attempts to find and return a device mounted on the panel specified, and on failure to find one it will return the first device listed
        /// </summary>
        /// <param name="desiredPanel">The desired panel on which the returned device should be mounted, if available</param>
        /// <returns></returns>
        private static async Task <DeviceInformation> FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel desiredPanel)
        {
            // Get available devices for capturing pictures
            var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            // Write out all discovered device info to debug output
            foreach (var videoDevice in allVideoDevices)
            {
                Debug.WriteLine($"\n********* Properties for {videoDevice?.Name} **********");

                foreach (var prop in videoDevice?.Properties)
                {
                    Debug.WriteLine($"Key: {prop.Key}, Value: {prop.Value}");
                }

                Debug.WriteLine($"*********************************************************\n");
            }

            // Get the desired camera by panel
            DeviceInformation desiredDevice = allVideoDevices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == desiredPanel);

            // If there is no device mounted on the desired panel, return the first device found
            return(desiredDevice ?? allVideoDevices.FirstOrDefault());
        }
        public MainViewModel()
        {
            PreviewVideoElementLoadedCommand = new RelayCommand<FrameworkElement>(OnFrameworkElementLoaded);
            m_configurationPropertySet = new PropertySet();

            Application.Current.Suspending += OnApplicationSuspending;
            Application.Current.Resuming += OnApplicationResuming;
            SystemMediaTransportControls.GetForCurrentView().PropertyChanged += OnMediaPropertyChanged;
            
            CaptureCommand = new RelayCommand(OnCaptureImage, CanExecuteCaptureImage);
            ToggleCameraCommand = new RelayCommand(OnToggleCamera, CanExecuteToggleCamera);

            Effects = CreateEditableEffects();
            NonEditableEffects = CreateNonEditableEffects();

            m_imageConsumerEffect = m_contrastEffect;
            m_imageProviderEffect = m_brightnessEffect;

            m_desiredCameraPanel = Windows.Devices.Enumeration.Panel.Back;

            UpdateConfiguration();

            CurrentState = "Normal";
            CurrentEditor = Effects.FirstOrDefault();
            
            m_externalCamera = false;
            m_isToggelingCamera = false;
        }
        private async void InitCam(Windows.Devices.Enumeration.Panel panel)
        {
            try
            {
                //rectCrop.Visibility = Visibility.Collapsed;

                StorageFile file = await Converter.WriteableBitmapToStorageFile(new WriteableBitmap(384, 384), Converter.FileFormat.Jpeg);

                await rectCrop.LoadImage(file);

                if (captureManager != null)
                {
                    await captureManager.StopPreviewAsync();

                    this.capture.Source = null;
                }

                captureManager = new MediaCapture();
                var cameraDevice = await FindCameraDeviceByPanelAsync(panel);

                var settings = new MediaCaptureInitializationSettings {
                    VideoDeviceId = cameraDevice.Id
                };
                await captureManager.InitializeAsync(settings);

                capture.Source = captureManager;

                string currentorientation = DisplayInformation.GetForCurrentView().CurrentOrientation.ToString();
                switch (currentorientation)
                {
                case "Landscape":
                    captureManager.SetPreviewRotation(VideoRotation.None);
                    break;

                case "Portrait":
                    captureManager.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
                    break;

                case "LandscapeFlipped":
                    captureManager.SetPreviewRotation(VideoRotation.Clockwise180Degrees);
                    break;

                case "PortraitFlipped":
                    captureManager.SetPreviewRotation(VideoRotation.Clockwise270Degrees);
                    break;

                default:
                    captureManager.SetPreviewRotation(VideoRotation.None);
                    break;
                }

                var torch = captureManager.VideoDeviceController.TorchControl;
                if (torch.Supported)
                {
                    if (flashMode == 1)
                    {
                        captureManager.VideoDeviceController.FlashControl.Enabled = false;
                    }
                    else if (flashMode == 0)
                    {
                        captureManager.VideoDeviceController.FlashControl.Enabled = true;
                    }
                }

                await captureManager.StartPreviewAsync();

                //if (GetDisplayAspectRatio() == DisplayAspectRatio.FifteenByNine)
                //{
                //    GetFifteenByNineBounds();
                //}
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
        private static async Task<DeviceInformation> GetCameraID(Panel camera)
        {
            var deviceID = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture))
                .FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == camera);

            return deviceID;
        }
        private async Task InitiateCameraCaptureObject(Panel deviceLocation)
        {
            try
            {
                if (_bInitializingCamera || _cameraCapture != null) return;
                _bInitializingCamera = true;
                await InitCaptureSettings(deviceLocation);
                _cameraCapture = new MediaCapture();
                await _cameraCapture.InitializeAsync(_captureInitSettings);
                //Enable QR Detector
                if (_qrDetectionModeEnabled)
                {
                    var formats = _cameraCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo);
                    var format = (VideoEncodingProperties)formats.OrderBy((item) =>
                    {
                        var props = (VideoEncodingProperties)item;
                        return Math.Abs(props.Height - ActualWidth) + Math.Abs(props.Width - ActualHeight);
                    }).First();
                    await _cameraCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, format);
                    var definition = new LumiaAnalyzerDefinition(ColorMode.Yuv420Sp, format.Width >= format.Height ? format.Width : format.Height, AnalyzeImage);
                    await _cameraCapture.AddEffectAsync(MediaStreamType.VideoPreview, definition.ActivatableClassId, definition.Properties);
                    _barcodeReader = _barcodeReader ?? new BarcodeReader
                    {
                        Options = new DecodingOptions
                        {
                            PossibleFormats = new[] { BarcodeFormat.QR_CODE, BarcodeFormat.CODE_128 },
                            TryHarder = true
                        }
                    };
                }

                PhotoPreview.Source = _cameraCapture;
                await _cameraCapture.StartPreviewAsync();
                _cameraCapture.Failed += CameraCaptureOnFailed;
                _scannerAutoFocus = await ScannerAutoFocus.StartAsync(_cameraCapture.VideoDeviceController.FocusControl);
                _cameraCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
            }
            catch (Exception ex)
            {
                WindowsPhoneUtils.Log(ex.Message);
            }
            _bInitializingCamera = false;
        }
        private async Task InitCaptureSettings(Panel deviceLocation)
        {
            try
            {
                _deviceList = _deviceList ?? await WindowsPhoneUtils.EnumerateDevices(DeviceClass.VideoCapture);
                var deviceSelected = _deviceList.FirstOrDefault(camera => camera.IsEnabled && camera.EnclosureLocation != null && camera.EnclosureLocation.Panel == deviceLocation);
                deviceSelected = deviceSelected ?? (_deviceList.Count > 0 ? _deviceList[0] : null);

                if (deviceSelected == null) return;
                _captureInitSettings = new MediaCaptureInitializationSettings()
                {
                    StreamingCaptureMode = StreamingCaptureMode.Video,
                    PhotoCaptureSource = PhotoCaptureSource.VideoPreview,
                    VideoDeviceId = deviceSelected.Id
                };
            }
            catch (Exception ex)
            {
                WindowsPhoneUtils.Log("No camera suitable found");
            }
        }
 private async void OnToggleCamera()
 {
     m_isToggelingCamera = true;
     UpdateButtonState();
     await StopPreviewAsync();
     if (m_desiredCameraPanel == Windows.Devices.Enumeration.Panel.Back)
     {
         m_desiredCameraPanel = Windows.Devices.Enumeration.Panel.Front;
     }
     else
     {
         m_desiredCameraPanel = Windows.Devices.Enumeration.Panel.Back;
     }
     await StartPreviewAsync();
     m_isToggelingCamera = false;
     UpdateButtonState();
 }
        private async Task<DeviceInformation> FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel desiredPanel)
        {
            // Get available devices for capturing pictures
            var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            m_hasFrontAndBackCamera = allVideoDevices.Any(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front) &&
                allVideoDevices.Any(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);

            // Get the desired camera by panel
            DeviceInformation desiredDevice = allVideoDevices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == desiredPanel);

            // If there is no device mounted on the desired panel, use the first device found
            desiredDevice = desiredDevice ?? allVideoDevices.FirstOrDefault();
            if (desiredDevice != null)
            {
                m_desiredCameraPanel = desiredPanel;
                m_mirroringPreview = desiredPanel == Windows.Devices.Enumeration.Panel.Front;
                if (desiredDevice.EnclosureLocation == null || desiredDevice.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Unknown)
                {
                    // No information on the location of the camera, assume it's an external camera, not integrated on the device
                    m_externalCamera = true;
                }
                else
                {
                    m_externalCamera = false;
                }
            }

            return desiredDevice;
        }
Exemple #29
0
        private async Task <MediaCaptureInitializationSettings> GetMediaCaptureSettingsAsync(Windows.Devices.Enumeration.Panel panel, int width, int height, int frameRate)
        {
            string deviceId = string.Empty;

            // Finds all video capture devices
            DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            foreach (var device in devices)
            {
                // Check if the device on the requested panel supports Video Profile
                if (MediaCapture.IsVideoProfileSupported(device.Id) && device.EnclosureLocation.Panel == panel)
                {
                    // We've located a device that supports Video Profiles on expected panel
                    deviceId = device.Id;
                    break;
                }
            }
            MediaCaptureInitializationSettings mediaInitSettings = new MediaCaptureInitializationSettings {
                VideoDeviceId = deviceId
            };
            IReadOnlyList <MediaCaptureVideoProfile> profiles = MediaCapture.FindAllVideoProfiles(deviceId);

            var match = (from profile in profiles
                         from desc in profile.SupportedRecordMediaDescription
                         where desc.Width == width && desc.Height == height && Math.Round(desc.FrameRate) == frameRate
                         select new { profile, desc }).FirstOrDefault();

            if (match != null)
            {
                mediaInitSettings.VideoProfile           = match.profile;
                mediaInitSettings.RecordMediaDescription = match.desc;
            }
            else
            {
                // Could not locate rofile, use default video recording profile
                mediaInitSettings.VideoProfile = deviceId == String.Empty ? null : profiles[0];
            }
            return(mediaInitSettings);
        }