public async System.Threading.Tasks.Task StartCapturePreviewAsync() { try { Windows.Devices.Enumeration.Panel devicePanel = Windows.Devices.Enumeration.Panel.Back; var obj = Global.Current.LocalSettings.LoadData(conCameraPanel); if (obj != null && obj.ToString() == conCameraFront) { devicePanel = Windows.Devices.Enumeration.Panel.Front; this.captureElement.FlowDirection = Windows.UI.Xaml.FlowDirection.RightToLeft; } else { this.captureElement.FlowDirection = Windows.UI.Xaml.FlowDirection.LeftToRight; } if ((App.Current as App).mediaCapture == null) { await(App.Current as App).InitializeCapture(devicePanel); } Global.Current.LocalSettings.SaveData(conCameraPanel, devicePanel.ToString()); this.mediaCapture = (App.Current as App).mediaCapture; this.zoomControl = this.mediaCapture.VideoDeviceController.ZoomControl; if (this.mediaCapture.VideoDeviceController.FocusControl.Supported) { var focusSettings = new FocusSettings(); focusSettings.AutoFocusRange = AutoFocusRange.FullRange; focusSettings.Mode = FocusMode.Auto; focusSettings.WaitForFocus = true; focusSettings.DisableDriverFallback = false; this.mediaCapture.VideoDeviceController.FocusControl.Configure(focusSettings); } if (this.zoomControl != null && this.zoomControl.Supported) { this.zoomSlider.Visibility = Windows.UI.Xaml.Visibility.Visible; this.zoomSlider.IsEnabled = true; this.zoomSlider.Maximum = this.zoomControl.Max; this.zoomSlider.Minimum = this.zoomControl.Min; this.zoomSlider.StepFrequency = this.zoomControl.Step; this.zoomSlider.Value = this.zoomControl.Value; } else { this.zoomSlider.Visibility = Windows.UI.Xaml.Visibility.Collapsed; } this.AppbarSwitchCamera.IsEnabled = (App.Current as App).isSupportFront; await this.mediaCapture.VideoDeviceController.ExposureControl.SetAutoAsync(true); this.captureElement.Source = this.mediaCapture; await this.mediaCapture.StartPreviewAsync(); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
public async System.Threading.Tasks.Task StartCapturePreviewAsync() { try { Windows.Devices.Enumeration.Panel devicePanel = Windows.Devices.Enumeration.Panel.Back; var obj = Global.Current.LocalSettings.LoadData(conCameraPanel); if (obj != null && obj.ToString() == conCameraFront) { devicePanel = Windows.Devices.Enumeration.Panel.Front; this.captureElement.FlowDirection = Windows.UI.Xaml.FlowDirection.RightToLeft; } else { this.captureElement.FlowDirection = Windows.UI.Xaml.FlowDirection.LeftToRight; } if ((App.Current as App).mediaCapture == null) { await(App.Current as App).InitializeCapture(devicePanel); } if ((App.Current as App).isExternalCamera) { this.captureElement.FlowDirection = Windows.UI.Xaml.FlowDirection.RightToLeft; } Global.Current.LocalSettings.SaveData(conCameraPanel, devicePanel.ToString()); this.mediaCapture = (App.Current as App).mediaCapture; this.zoomControl = this.mediaCapture.VideoDeviceController.Zoom; if (this.zoomControl != null && this.zoomControl.Capabilities.Supported) { this.zoomSlider.Visibility = Windows.UI.Xaml.Visibility.Visible; this.zoomSlider.IsEnabled = true; this.zoomSlider.Maximum = this.zoomControl.Capabilities.Max; this.zoomSlider.Minimum = this.zoomControl.Capabilities.Min; this.zoomSlider.StepFrequency = this.zoomControl.Capabilities.Step; double value; var rev = this.zoomControl.TryGetValue(out value); if (rev) { this.zoomSlider.Value = value; } } else { this.zoomSlider.Visibility = Windows.UI.Xaml.Visibility.Collapsed; } this.AppbarSwitchCamera.Visibility = (App.Current as App).isSupportFront?Visibility.Visible:Visibility.Collapsed; this.AppbarFlashAuto.Visibility = this.mediaCapture.VideoDeviceController.FlashControl.Supported ? Visibility.Visible : Visibility.Collapsed; this.captureElement.Source = this.mediaCapture; await this.mediaCapture.StartPreviewAsync(); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }