예제 #1
0
        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();
                }
            }
        }
예제 #2
0
        /// <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;
        }
예제 #3
0
        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));
            }
        }
예제 #4
0
        /// <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;
            }
        }
예제 #5
0
        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;
        }
예제 #6
0
 private async Task FocusAsyncInternal()
 {
     if (_inited)
     {
         if (!_focusing && PhotoCaptureDevice.IsFocusSupported(_device.SensorLocation))
         {
             _focusing = true;
             try
             {
                 await _device.FocusAsync();
             }
             finally
             {
                 _focusing = false;
             }
         }
     }
 }
예제 #7
0
        /// <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;
        }