Example #1
0
 /// <summary>
 /// The <see cref="MediaViewer.ItemUnzoomed"/> event handler.
 /// </summary>
 /// <param name="sender">Event sender.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 private void MediaViewerOnItemUnzoomed(object sender, EventArgs e)
 {
     if (!this.ApplicationBar.IsVisible)
     {
         DispatcherHelper.BeginInvokeOnUIThread(this.RefreshAppBar);
     }
 }
        /// <summary>
        /// The <see cref="PhotoCamera.PhotoCaptured"/> event handler.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="capturedPhoto">Captured photo.</param>
        private void CameraOnPhotoCaptured(object sender, ICapturedPhoto capturedPhoto)
        {
            // In our application we capture only single frame, so we can update view model state in
            // the current method.
            // If your application captures multiple frames, you may want to modify the 'CameraOnCaptureStopped'
            // method or add additional logic here.
            DispatcherHelper.BeginInvokeOnUIThread(async() =>
            {
                this.State = MainPageViewModelState.SavingCaptureResult;
                this.NotifyFocusStateChanged(new FocusStateChangedEventArgs(FocusState.Unlocked));

                try
                {
                    using (capturedPhoto)
                    {
                        IThumbnailedImage image = await this.storageService.SaveResultToCameraRollAsync(capturedPhoto);

                        // Get the preview image.
                        BitmapImage source = new BitmapImage();
                        source.SetSource(image.GetThumbnailImage());

                        this.Items.Add(image);
                        this.ReviewImageBrush = new ImageBrush {
                            ImageSource = source
                        };
                    }
                }
                finally
                {
                    this.State = MainPageViewModelState.Loaded;
                }
            });
        }
Example #3
0
 public static void TrackAsyncAction <T>(IAsyncOperation <T> action, AsyncOperationCompletedHandler <T> completed)
 {
     DisableView(null);
     action.Completed = (s, e) => DispatcherHelper.BeginInvokeOnUIThread(() =>
     {
         EnableView();
         completed(s, e);
     });
 }
        /// <summary>
        /// Stops the video preview.
        /// </summary>
        protected override void DoWork()
        {
            DispatcherHelper.BeginInvokeOnUIThread(async() =>
            {
                await this.CameraController.StopPreviewAsync();

                Tracing.Trace("StopPreviewTask: Camera preview stopped.");
                this.NotifyCompleted();
            });
        }
Example #5
0
 public static void TrackAsyncAction <T, TProgress>(IAsyncOperationWithProgress <T, TProgress> action, Func <TProgress, double> progressConverter, AsyncOperationWithProgressCompletedHandler <T, TProgress> completed)
 {
     DisableView(null);
     action.Completed = (s, e) => DispatcherHelper.BeginInvokeOnUIThread(() =>
     {
         EnableView();
         completed(s, e);
     });
     action.Progress = (s, p) => DispatcherHelper.BeginInvokeOnUIThread(() => DisableView(progressConverter(p)));
 }
        /// <summary>
        /// Stops the photo capture operation.
        /// </summary>
        protected override void DoWork()
        {
            DispatcherHelper.BeginInvokeOnUIThread(async() =>
            {
                await this.photoCapture.StopAsync();

                Tracing.Trace("StopPhotoCaptureTask: Photo capture stopped.");
                this.NotifyCompleted();
            });
        }
        /// <summary>
        /// Loads and initializes the <see cref="CameraController"/> object.
        /// </summary>
        protected override void DoWork()
        {
            // Must be done in the UI thread context.
            DispatcherHelper.BeginInvokeOnUIThread(async() =>
            {
                await this.CameraController.InitializeAsync();

                Tracing.Trace("LoadCameraTask: Camera loaded.");
                this.NotifyCompleted();
            });
        }
Example #8
0
 static GalleryImage()
 {
     DispatcherHelper.BeginInvokeOnUIThread(() =>
     {
         display      = DisplayInformation.GetForCurrentView();
         DefaultThumb = new BitmapImage();
         DefaultThumb.Dispatcher.BeginIdle(async a =>
         {
             using (var stream = await StorageHelper.GetIconOfExtension("jpg"))
             {
                 await DefaultThumb.SetSourceAsync(stream);
             }
         });
     });
 }
Example #9
0
        /// <summary>
        /// The <see cref="MainPageViewModel.FocusStateChanged"/> event handler.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">The <see cref="FocusStateChangedEventArgs"/> instance containing the event data.</param>
        private void ViewModelOnFocusStateChanged(object sender, FocusStateChangedEventArgs e)
        {
            DispatcherHelper.BeginInvokeOnUIThread(() =>
            {
                switch (e.FocusState)
                {
                case FocusState.Focusing:
                    if (this.viewfinder != null)
                    {
                        if (e.FocusPoint.HasValue)
                        {
                            this.viewfinder.FlashPointFocusBrackets(e.FocusPoint.Value);
                        }
                        else
                        {
                            this.viewfinder.FlashAutoFocusBrackets();
                        }
                    }

                    break;

                case FocusState.Locked:
                    if (this.viewfinder != null)
                    {
                        if (e.FocusPoint.HasValue)
                        {
                            this.viewfinder.LockTouchFocusBrackets();
                        }
                        else
                        {
                            this.viewfinder.LockAutoFocusBrackets();
                        }
                    }

                    break;

                case FocusState.Unlocked:
                    if (this.viewfinder != null)
                    {
                        this.viewfinder.DismissFocusBrackets();
                    }

                    break;
                }
            });
        }
Example #10
0
        /// <summary>
        /// Updates photo capture in accordance with the current application parameters.
        /// </summary>
        /// <returns>Awaitable task.</returns>
        private async Task UpdatePhotoCaptureAsync()
        {
            bool needToUpdateAgain = false;
            Size resolution        = this.FindHighestSupportedPhotoResolution();

            ImageEncodingProperties encoding = ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8);

            encoding.Width  = unchecked ((uint)resolution.Width);
            encoding.Height = unchecked ((uint)resolution.Height);

            try
            {
                await this.camera.InitializePhotoCaptureAsync(
                    this.CaptureMode,
                    new CaptureParameters
                {
                    ImageEncoding = encoding,
                    FlashMode     = this.FlashMode
                });
            }
            catch
            {
                // VPS may not be supported on the current device.
                if (this.CaptureMode == CaptureMode.Variable)
                {
                    // Fall back to the LowLag photo capture.
                    this.CaptureMode  = CaptureMode.LowLag;
                    needToUpdateAgain = true;

                    // Show the error message to the user.
                    DispatcherHelper.BeginInvokeOnUIThread(() => MessageBox.Show(AppResources.VpsNotSupportedMessage, AppResources.VpsNotSupportedCaption, MessageBoxButton.OK));
                }
                else
                {
                    throw;
                }
            }

            // Call this method again, if the VPS initialization failed, so we'll reinitialize LLPC.
            if (needToUpdateAgain)
            {
                await this.UpdatePhotoCaptureAsync();
            }
        }
Example #11
0
 public static void SendToast(string content, Type source)
 {
     if (!Available)
     {
         return;
     }
     if (content == null)
     {
         throw new ArgumentNullException(nameof(content));
     }
     DispatcherHelper.BeginInvokeOnUIThread(() =>
     {
         if (source != null && source != root.fm_inner.Content?.GetType())
         {
             return;
         }
         root.FindName(nameof(root.bd_Toast));
         root.tb_Toast.Text       = content;
         root.bd_Toast.Visibility = Visibility.Visible;
         PlayToastPanel.Begin();
     });
 }
Example #12
0
 /// <summary>
 /// The <see cref="MediaViewer.ItemZoomed"/> event handler.
 /// </summary>
 /// <param name="sender">Event sender.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 private void MediaViewerOnItemZoomed(object sender, EventArgs e)
 {
     DispatcherHelper.BeginInvokeOnUIThread(() => this.ApplicationBar.IsVisible = false);
 }
Example #13
0
 public static void TrackAsyncAction <T>(IAsyncOperation <T> action)
 {
     DisableView(null);
     action.Completed = (s, e) => DispatcherHelper.BeginInvokeOnUIThread(EnableView);
 }