Пример #1
0
        /// <summary>
        /// Triggered when webcam feed loads both for the first time and every time page is navigated to.
        /// If no WebcamHelper has been created, it creates one. Otherwise, simply restarts webcam preview feed on page.
        /// </summary>
        private async void WebcamFeed_Loaded(object sender, RoutedEventArgs e)
        {
            if (webcam == null || !webcam.IsInitialized())
            {
                webcam = new UsbCamera();
                await webcam.InitializeAsync();
                WebcamFeed.Source = webcam.MediaCaptureInstance;

                // Check to make sure MediaCapture isn't null before attempting to start preview. Will be null if no camera is attached.
                if (WebcamFeed.Source != null)
                {
                    await webcam.StartCameraPreview();
                }
            }
            else if (webcam.IsInitialized())
            {
                WebcamFeed.Source = webcam.MediaCaptureInstance;

                // Check to make sure MediaCapture isn't null before attempting to start preview. Will be null if no camera is attached.
                if (WebcamFeed.Source != null)
                {
                    await webcam.StartCameraPreview();
                }
            }
        }
Пример #2
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     try
     {
         //Sets passed through WecamHelper from MainPage as local webcam object
         webcam = e.Parameter as UsbCamera;
     }
     catch (Exception exception)
     {
         Debug.WriteLine("Error when navigating to NewUserPage: " + exception.Message);
     }
 }