public static async Task ConfigureMedia(CaptureElement captureElement, LookupItemDTO cameraDevice, bool useHighRes) { if (cameraDevice != null) { if (captureElement.Source != null) { await captureElement.Source.StopPreviewAsync(); captureElement.Source = null; } var mediaCapture = new MediaCapture(); await mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.ValueLong }); try { var resolutions = mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).Select(x => x as VideoEncodingProperties); double ratio = 480.00 / 640.00; VideoEncodingProperties imageResolution = null; //If using High Resolution, pick the largest resolution with the same aspect ratio as the default photo size, // if not pick the resolution with the same aspect ratio and where the width is greater than or equal to the default photo size if (!useHighRes) { imageResolution = resolutions.Where(x => x.Width >= 640.00 && ratio == ((double)x.Height / (double)x.Width)).OrderBy(x => x.Height * x.Width).FirstOrDefault(); } if (imageResolution == null || useHighRes) { imageResolution = resolutions.Where(x => ratio == ((double)x.Height / (double)x.Width)).OrderByDescending(x => x.Height * x.Width).FirstOrDefault(); } if (imageResolution != null) { await mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, imageResolution); } } catch { //TODO: Swallow the error for now, some devices don't support MediaStreamType.Photo and i haven't found a good solution to handle this yet } mediaCapture.VideoDeviceController.PrimaryUse = CaptureUse.Photo; captureElement.Source = mediaCapture; captureElement.Stretch = Windows.UI.Xaml.Media.Stretch.UniformToFill; await mediaCapture.StartPreviewAsync(); } }
public static LookupItemDTO GetNextCamera(IEnumerable <LookupItemDTO> availableCameras, string currentCamera, bool saveAsDefault) { LookupItemDTO nextCamera = null; if (availableCameras != null && availableCameras.Any()) { nextCamera = availableCameras.First(x => x.ValueLong.Contains("VID_19AB&PID_2000")); if (nextCamera == null) { nextCamera = availableCameras.First(); } } return(nextCamera); }