public void Initialize(CameraSettingsActivatedEventArgs args) { videoDevController = (VideoDeviceController)args.VideoDeviceController; if (args.VideoDeviceExtension != null) { lcWrapper = new WinRTComponent(); lcWrapper.Initialize(args.VideoDeviceExtension); } bool bAuto = false; double value = 0.0; if (videoDevController.Brightness.Capabilities.Step != 0) { slBrt.Minimum = videoDevController.Brightness.Capabilities.Min; slBrt.Maximum = videoDevController.Brightness.Capabilities.Max; slBrt.StepFrequency = videoDevController.Brightness.Capabilities.Step; videoDevController.Brightness.TryGetValue(out value); slBrt.Value = value; } else { slBrt.IsEnabled = false; } if (videoDevController.Brightness.Capabilities.AutoModeSupported) { videoDevController.Brightness.TryGetAuto(out bAuto); tsBrtAuto.IsOn = bAuto; } else { tsBrtAuto.IsOn = false; tsBrtAuto.IsEnabled = false; } if (videoDevController.Contrast.Capabilities.Step != 0) { slCrt.Minimum = videoDevController.Contrast.Capabilities.Min; slCrt.Maximum = videoDevController.Contrast.Capabilities.Max; slCrt.StepFrequency = videoDevController.Contrast.Capabilities.Step; videoDevController.Contrast.TryGetValue(out value); slCrt.Value = value; } else { slCrt.IsEnabled = false; } if (videoDevController.Contrast.Capabilities.AutoModeSupported) { videoDevController.Contrast.TryGetAuto(out bAuto); tsCrtAuto.IsOn = bAuto; } else { tsCrtAuto.IsOn = false; tsCrtAuto.IsEnabled = false; } if (videoDevController.Focus.Capabilities.Step != 0) { slFocus.Minimum = videoDevController.Focus.Capabilities.Min; slFocus.Maximum = videoDevController.Focus.Capabilities.Max; slFocus.StepFrequency = videoDevController.Focus.Capabilities.Step; videoDevController.Focus.TryGetValue(out value); slFocus.Value = value; } else { slFocus.IsEnabled = false; } if (videoDevController.Focus.Capabilities.AutoModeSupported) { videoDevController.Focus.TryGetAuto(out bAuto); tsFocusAuto.IsOn = bAuto; } else { tsFocusAuto.IsOn = false; tsFocusAuto.IsEnabled = false; } if (videoDevController.Exposure.Capabilities.Step != 0) { slExp.Minimum = videoDevController.Exposure.Capabilities.Min; slExp.Maximum = videoDevController.Exposure.Capabilities.Max; slExp.StepFrequency = videoDevController.Exposure.Capabilities.Step; videoDevController.Exposure.TryGetValue(out value); slExp.Value = value; } else { slExp.IsEnabled = false; } if (videoDevController.Exposure.Capabilities.AutoModeSupported) { videoDevController.Exposure.TryGetAuto(out bAuto); tsExpAuto.IsOn = bAuto; } else { tsExpAuto.IsOn = false; tsExpAuto.IsEnabled = false; } if (lcWrapper != null) { slEffect.Minimum = 0; slEffect.Maximum = 100; slEffect.StepFrequency = 1; DspSettings dspSettings = lcWrapper.GetDspSetting(); slEffect.Value = dspSettings.percentOfScreen; if (dspSettings.isEnabled == 1) { tsEffectEnabled.IsOn = true; } else { tsEffectEnabled.IsOn = false; slEffect.IsEnabled = false; } } else { tsEffectEnabled.IsEnabled = false; slEffect.IsEnabled = false; } }
private void Cleanup() { System.Diagnostics.Debug.WriteLine("Cleaning up scanner"); try { _Ready = false; _Done = true; _Rendering = true; _Controller = null; _ImagePreview = null; _Effects = null; _Render.Dispose(); _Render = null; _Image = null; _Source.StopPreviewAsync(); _Source.PreviewFrameAvailable -= OnPreviewFrameAvailable; _Source.Dispose(); _Source = null; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Cleaning up scanner. {0}", ex.Message); } }
private async void Init() { //Get back camera var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); var backCameraId = devices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Panel.Back).Id; //Start preview _cameraPreviewImageSource = new CameraPreviewImageSource(); await _cameraPreviewImageSource.InitializeAsync(backCameraId); var properties = await _cameraPreviewImageSource.StartPreviewAsync(); //Setup preview _width = 640.0; _height = (_width / properties.Width) * properties.Height; var bitmap = new WriteableBitmap((int)_width, (int)_height); _writeableBitmap = bitmap; PreviewImage.Source = _writeableBitmap; _writeableBitmapRenderer = new WriteableBitmapRenderer(_cameraPreviewImageSource, _writeableBitmap); _cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable; _videoDevice = (VideoDeviceController)_cameraPreviewImageSource.VideoDeviceController; //Set timer for auto focus if (_videoDevice.FocusControl.Supported) { var focusSettings = new FocusSettings { AutoFocusRange = AutoFocusRange.Macro, Mode = FocusMode.Auto, WaitForFocus = false, DisableDriverFallback = false }; _videoDevice.FocusControl.Configure(focusSettings); _timer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 2, 0) }; _timer.Tick += TimerOnTick; _timer.Start(); } await _videoDevice.ExposureControl.SetAutoAsync(true); _initialized = true; }
private async Task InitCamera() { var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture); string deviceId = devices.FirstOrDefault(d => d.EnclosureLocation.Panel != Windows.Devices.Enumeration.Panel.Front).Id; _Source = new CameraPreviewImageSource(); await _Source.InitializeAsync(deviceId); _Source.PreviewFrameAvailable += OnPreviewFrameAvailable; // set auto focus _Controller = (VideoDeviceController)_Source.VideoDeviceController; if (_Controller.FocusControl.Supported) { try { if (_Controller.FocusControl.WaitForFocusSupported) { _Controller.FocusControl.Configure(new FocusSettings { Mode = FocusMode.Continuous }); } else { _Controller.FocusControl.Configure(new FocusSettings { Mode = FocusMode.Auto }); } } catch { _Controller.FocusControl.Configure(new FocusSettings { Mode = FocusMode.Auto }); } } if (_Controller.FlashControl.Supported) _Controller.FlashControl.Auto = true; if (_Controller.ExposureControl.Supported) _Controller.ExposureControl.SetAutoAsync(true); _Image = new WriteableBitmap((int)Window.Current.Bounds.Width, (int)Window.Current.Bounds.Height); // filters _Effects = new FilterEffect(_Source); _Effects.Filters = new IFilter[] { new GrayscaleFilter() }; _Render = new WriteableBitmapRenderer(_Effects, _Image); _Ready = true; }