private async void Canvas_Tap(object sender, System.Windows.Input.GestureEventArgs e) { if (!_focusing && !_capturing) { _focusing = true; var point = e.GetPosition(Canvas); var scaleX = _device.PreviewResolution.Width / Canvas.ActualWidth; var scaleY = _device.PreviewResolution.Height / Canvas.ActualHeight; // Show focusing bracket and set focus region if supported by the HW if (PhotoCaptureDevice.IsFocusRegionSupported(SENSOR_LOCATION)) { FocusBracket.RenderTransform = new TranslateTransform() { X = point.X, Y = point.Y }; FocusBracket.Visibility = Visibility.Visible; _device.FocusRegion = new Windows.Foundation.Rect(point.X * scaleX, point.Y * scaleY, 1, 1); } // Focus and capture if focus is supported by the HW, otherwise just capture if (PhotoCaptureDevice.IsFocusSupported(SENSOR_LOCATION)) { CameraFocusStatus status; try { status = await _device.FocusAsync(); } catch (Exception) { status = CameraFocusStatus.NotLocked; } _focusing = false; FocusBracket.Visibility = Visibility.Collapsed; if (status == CameraFocusStatus.Locked) { await CaptureAsync(); } } else { await CaptureAsync(); } } }
/// <summary> /// Uninitializes photo capture device and unwires device hardware capture keys. /// </summary> private void UninitializeCamera() { if (PhotoCaptureDevice.IsFocusSupported(SENSOR_LOCATION)) { Microsoft.Devices.CameraButtons.ShutterKeyHalfPressed -= CameraButtons_ShutterKeyHalfPressed; } Microsoft.Devices.CameraButtons.ShutterKeyPressed -= CameraButtons_ShutterKeyPressed; _device.Dispose(); _device = null; }
public async Task AutoFocusAsync() { if (!_isInitialized || !_isFocused && PhotoCaptureDevice.IsFocusSupported(Device.SensorLocation)) { SendFocused(new FocusedEventArgs(CameraFocusStatus.NotLocked)); CameraFocusStatus focusState = await Device.FocusAsync(); _isFocused = focusState == CameraFocusStatus.Locked; SendFocused(new FocusedEventArgs(focusState)); } }
/// <summary> /// Starts autofocusing, if supported. Capturing buttons are disabled while focusing. /// </summary> private async Task AutoFocus() { if (!_capturing && PhotoCaptureDevice.IsFocusSupported(_dataContext.Device.SensorLocation)) { SetScreenButtonsEnabled(false); SetCameraButtonsEnabled(false); await _dataContext.Device.FocusAsync(); SetScreenButtonsEnabled(true); SetCameraButtonsEnabled(true); _capturing = false; } }
private async void Focusing() { while (!stop) { if (PhotoCaptureDevice.IsFocusSupported(sensorLocation)) { await PhotoCaptureDevice.FocusAsync(); } else { System.Threading.Thread.Sleep(200); } } PhotoCaptureDevice.PreviewFrameAvailable -= PreviewFrame; PhotoCaptureDevice.Dispose(); PhotoCaptureDevice = null; }
private async Task FocusAsyncInternal() { if (_inited) { if (!_focusing && PhotoCaptureDevice.IsFocusSupported(_device.SensorLocation)) { _focusing = true; try { await _device.FocusAsync(); } finally { _focusing = false; } } } }
/// <summary> /// Synchronously initializes the photo capture device for a high resolution photo capture. /// Viewfinder video stream is sent to a VideoBrush element called ViewfinderVideoBrush, and /// device hardware capture key is wired to the CameraButtons_ShutterKeyHalfPressed and /// CameraButtons_ShutterKeyPressed methods. /// </summary> private void InitializeCamera() { Windows.Foundation.Size captureResolution; var deviceName = DeviceStatus.DeviceName; if (deviceName.Contains("RM-875") || deviceName.Contains("RM-876") || deviceName.Contains("RM-877")) { captureResolution = new Windows.Foundation.Size(7712, 4352); // 16:9 //captureResolution = new Windows.Foundation.Size(7136, 5360); // 4:3 } else if (deviceName.Contains("RM-937") || deviceName.Contains("RM-938") || deviceName.Contains("RM-939")) { captureResolution = new Windows.Foundation.Size(5376, 3024); // 16:9 //captureResolution = new Windows.Foundation.Size(4992, 3744); // 4:3 } else { captureResolution = PhotoCaptureDevice.GetAvailableCaptureResolutions(SENSOR_LOCATION).First(); } var task = PhotoCaptureDevice.OpenAsync(SENSOR_LOCATION, captureResolution).AsTask(); task.Wait(); _device = task.Result; _device.SetProperty(KnownCameraGeneralProperties.PlayShutterSoundOnCapture, true); if (_flashButton != null) { SetFlashState(_flashState); } AdaptToOrientation(); ViewfinderVideoBrush.SetSource(_device); if (PhotoCaptureDevice.IsFocusSupported(SENSOR_LOCATION)) { Microsoft.Devices.CameraButtons.ShutterKeyHalfPressed += CameraButtons_ShutterKeyHalfPressed; } Microsoft.Devices.CameraButtons.ShutterKeyPressed += CameraButtons_ShutterKeyPressed; }