private async Task InitializeAsync() { VersionDescription = GetVersionDescription(); _setup = new SetupService(); bool res = await _setup.GetAutomode(); tglAutoOcr.IsOn = res; await Task.CompletedTask; }
public async Task InitializeCameraAsync() { try { if (_setup == null) { _setup = new SetupService(); } isAutoShot = await _setup.GetAutomode(); if (_mediaCapture == null) { _mediaCapture = new MediaCapture(); _mediaCapture.Failed += MediaCapture_Failed; _cameraDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); if (_cameraDevices == null || !_cameraDevices.Any()) { throw new NotSupportedException(); } DeviceInformation device; if (_cameraDevices.Count > 1) { device = _cameraDevices.FirstOrDefault(camera => camera.EnclosureLocation?.Panel == Windows.Devices.Enumeration.Panel.Back); } else { device = _cameraDevices.FirstOrDefault(camera => camera.EnclosureLocation?.Panel == Panel); } var cameraId = device?.Id ?? _cameraDevices.First().Id; await _mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings { VideoDeviceId = cameraId }); if (_mediaCapture.VideoDeviceController.FocusControl.Supported) { isAutoFocusCapable = true; errorMessage.Text = "VIZZoneInFront".GetLocalized(); } else { isAutoFocusCapable = false; errorMessage.Text = "NoFocusCamera".GetLocalized(); } IMediaEncodingProperties IProps = this._mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview); vep = (VideoEncodingProperties)IProps; DrawLineOnCanvas(vep.Width, vep.Height); if (Panel == Windows.Devices.Enumeration.Panel.Back) { //_mediaCapture.SetRecordRotation(VideoRotation.Clockwise90Degrees); //_mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees); _mirroringPreview = false; } else { _mirroringPreview = false; } IsInitialized = true; CanSwitch = _cameraDevices?.Count > 1; RegisterOrientationEventHandlers(); await StartPreviewAsync(); } } catch (UnauthorizedAccessException) { errorMessage.Text = "Camera_Exception_UnauthorizedAccess".GetLocalized(); } catch (NotSupportedException) { errorMessage.Text = "Camera_Exception_NotSupported".GetLocalized(); } catch (TaskCanceledException) { errorMessage.Text = "Camera_Exception_InitializationCanceled".GetLocalized(); } catch (Exception) { errorMessage.Text = "Camera_Exception_InitializationError".GetLocalized(); } }