Esempio n. 1
0
        // Provide touch focus in the viewfinder.
        async void focus_Tapped(object sender, GestureEventArgs e)
        {
            if (cam == null)
            {
                return;
            }


            Point uiTapPoint = e.GetPosition(viewfinderCanvas);

            if (PhotoCaptureDevice.IsFocusRegionSupported(cam.SensorLocation))
            {
                Size _focusRegionSize = new Size(100, 100);

                // Get tap coordinates as a foundation point
                Windows.Foundation.Point tapPoint = new Windows.Foundation.Point(uiTapPoint.X, uiTapPoint.Y);

                double xRatio = viewfinderCanvas.ActualHeight / cam.PreviewResolution.Width;
                double yRatio = viewfinderCanvas.ActualWidth / cam.PreviewResolution.Height;

                // adjust to center focus on the tap point
                Windows.Foundation.Point displayOrigin = new Windows.Foundation.Point(
                    tapPoint.Y - _focusRegionSize.Width / 2, (viewfinderCanvas.ActualWidth - tapPoint.X) - _focusRegionSize.Height / 2);

                // adjust for resolution difference between preview image and the canvas
                Windows.Foundation.Point viewFinderOrigin = new Windows.Foundation.Point(displayOrigin.X / xRatio, displayOrigin.Y / yRatio);

                Rect focusrect = new Rect(viewFinderOrigin, _focusRegionSize);

                // clip to preview resolution
                Rect viewPortRect = new Rect(0, 0, cam.PreviewResolution.Width, cam.PreviewResolution.Height);
                focusrect.Intersect(viewPortRect);

                cam.FocusRegion = focusrect;

                // show a focus indicator
                //focusBrackets.SetValue(Shape.StrokeProperty, new SolidColorBrush(Colors.Blue));
                focusBrackets.Visibility = Visibility.Visible;
                focusBrackets.SetValue(Canvas.LeftProperty, uiTapPoint.X - _focusRegionSize.Width / 2);
                focusBrackets.SetValue(Canvas.TopProperty, uiTapPoint.Y - _focusRegionSize.Height / 2);

                CameraFocusStatus status = await cam.FocusAsync();

                if (status == CameraFocusStatus.Locked)
                {
                    //focusBrackets.SetValue(Shape.StrokeProperty, new SolidColorBrush(Colors.Green));
                    cam.SetProperty(KnownCameraPhotoProperties.LockedAutoFocusParameters, AutoFocusParameters.Focus);
                }
                else
                {
                    cam.SetProperty(KnownCameraPhotoProperties.LockedAutoFocusParameters, AutoFocusParameters.None);
                }
            }
        }
Esempio n. 2
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));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Set autofocus area to tap location and refocus.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void videoCanvas_Tap(object sender, GestureEventArgs e)
        {
            System.Windows.Point uiTapPoint = e.GetPosition(VideoCanvas);

            if (PhotoCaptureDevice.IsFocusRegionSupported(_dataContext.Device.SensorLocation) && _focusSemaphore.WaitOne(0))
            {
                // Get tap coordinates as a foundation point
                Windows.Foundation.Point tapPoint = new Windows.Foundation.Point(uiTapPoint.X, uiTapPoint.Y);

                double xRatio = VideoCanvas.ActualHeight / _dataContext.Device.PreviewResolution.Width;
                double yRatio = VideoCanvas.ActualWidth / _dataContext.Device.PreviewResolution.Height;

                // adjust to center focus on the tap point
                Windows.Foundation.Point displayOrigin = new Windows.Foundation.Point(
                    tapPoint.Y - _focusRegionSize.Width / 2,
                    (VideoCanvas.ActualWidth - tapPoint.X) - _focusRegionSize.Height / 2);

                // adjust for resolution difference between preview image and the canvas
                Windows.Foundation.Point viewFinderOrigin = new Windows.Foundation.Point(displayOrigin.X / xRatio, displayOrigin.Y / yRatio);
                Windows.Foundation.Rect  focusrect        = new Windows.Foundation.Rect(viewFinderOrigin, _focusRegionSize);

                // clip to preview resolution
                Windows.Foundation.Rect viewPortRect = new Windows.Foundation.Rect(0, 0, _dataContext.Device.PreviewResolution.Width, _dataContext.Device.PreviewResolution.Height);
                focusrect.Intersect(viewPortRect);

                _dataContext.Device.FocusRegion = focusrect;

                // show a focus indicator
                FocusIndicator.SetValue(Shape.StrokeProperty, _notFocusedBrush);
                FocusIndicator.SetValue(Canvas.LeftProperty, uiTapPoint.X - _focusRegionSize.Width / 2);
                FocusIndicator.SetValue(Canvas.TopProperty, uiTapPoint.Y - _focusRegionSize.Height / 2);
                FocusIndicator.SetValue(Canvas.VisibilityProperty, Visibility.Visible);

                CameraFocusStatus status = await _dataContext.Device.FocusAsync();

                if (status == CameraFocusStatus.Locked)
                {
                    FocusIndicator.SetValue(Shape.StrokeProperty, _focusedBrush);
                    _manuallyFocused = true;
                    _dataContext.Device.SetProperty(KnownCameraPhotoProperties.LockedAutoFocusParameters,
                                                    AutoFocusParameters.Exposure & AutoFocusParameters.Focus & AutoFocusParameters.WhiteBalance);
                }
                else
                {
                    _manuallyFocused = false;
                    _dataContext.Device.SetProperty(KnownCameraPhotoProperties.LockedAutoFocusParameters, AutoFocusParameters.None);
                }

                _focusSemaphore.Release();
            }
        }
        private async void VideoCanvasOnTap(object sender, GestureEventArgs e)
        {
            try
            {
                System.Windows.Point uiTapPoint = e.GetPosition(VideoCanvas);

                if (PhotoCaptureDevice.IsFocusRegionSupported(PhotoCaptureDevice.SensorLocation) && _focusSemaphore.WaitOne(0))
                {
                    // Get tap coordinates as a foundation point
                    var tapPoint = new Windows.Foundation.Point(uiTapPoint.X, uiTapPoint.Y);

                    double xRatio = VideoCanvas.ActualHeight / PhotoCaptureDevice.PreviewResolution.Width;
                    double yRatio = VideoCanvas.ActualWidth / PhotoCaptureDevice.PreviewResolution.Height;

                    // adjust to center focus on the tap point
                    var displayOrigin = new Windows.Foundation.Point(
                        tapPoint.Y - _focusRegionSize.Width / 2,
                        (VideoCanvas.ActualWidth - tapPoint.X) - _focusRegionSize.Height / 2);

                    // adjust for resolution difference between preview image and the canvas
                    var viewFinderOrigin = new Windows.Foundation.Point(displayOrigin.X / xRatio, displayOrigin.Y / yRatio);
                    var focusrect        = new Windows.Foundation.Rect(viewFinderOrigin, _focusRegionSize);

                    // clip to preview resolution
                    var viewPortRect = new Windows.Foundation.Rect(0, 0, PhotoCaptureDevice.PreviewResolution.Width,
                                                                   PhotoCaptureDevice.PreviewResolution.Height);
                    focusrect.Intersect(viewPortRect);

                    PhotoCaptureDevice.FocusRegion = focusrect;

                    // show a focus indicator
                    FocusIndicator.SetValue(Shape.StrokeProperty, _notFocusedBrush);
                    FocusIndicator.SetValue(Canvas.LeftProperty, uiTapPoint.X - _focusRegionSize.Width / 2);
                    FocusIndicator.SetValue(Canvas.TopProperty, uiTapPoint.Y - _focusRegionSize.Height / 2);
                    FocusIndicator.SetValue(VisibilityProperty, Visibility.Visible);

                    CameraFocusStatus status = await PhotoCaptureDevice.FocusAsync();

                    if (status == CameraFocusStatus.Locked)
                    {
                        FocusIndicator.SetValue(Shape.StrokeProperty, _focusedBrush);
                        _manuallyFocused = true;
                        PhotoCaptureDevice.SetProperty(KnownCameraPhotoProperties.LockedAutoFocusParameters,
                                                       AutoFocusParameters.Exposure & AutoFocusParameters.Focus & AutoFocusParameters.WhiteBalance);
                    }
                    else
                    {
                        _manuallyFocused = false;
                        PhotoCaptureDevice.SetProperty(KnownCameraPhotoProperties.LockedAutoFocusParameters, AutoFocusParameters.None);
                    }

                    _focusSemaphore.Release();
                }

                await Capture();
            }
            catch (Exception exception)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    new CustomMessageDialog(
                        AppMessages.CaptureVideoFailed_Title,
                        String.Format(AppMessages.CaptureVideoFailed, exception.Message),
                        App.AppInformation,
                        MessageDialogButtons.Ok).ShowDialog();
                });
            }
        }
Esempio n. 5
0
 public FocusedEventArgs(CameraFocusStatus state)
 {
     State = state;
 }
 public FocusedEventArgs(CameraFocusStatus state)
 {
     State = state;
 }