예제 #1
0
        public void Dispose()
        {
            if (_cameraCaptureDevice != null)
            {
                _cameraCaptureDevice.Dispose();
            }

            if (_mediaLibrary != null)
            {
                _mediaLibrary.Dispose();
            }

            SaveSettings();
        }
예제 #2
0
 private void ShutDownCamera()
 {
     if (Camera != null)
     {
         Camera.Dispose();
         Camera = null;
     }
 }
예제 #3
0
        private void UninitializeCamera()
        {
            if (_device != null)
            {
                _device.PreviewFrameAvailable -= PhotoCaptureDevice_PreviewFrameAvailable;

                _device.Dispose();
                _device = null;
            }
        }
예제 #4
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;
        }
예제 #5
0
        // Gets the configuration of the specified camera
        private async Task <CameraConfig> GetCameraConfiguration(
            CameraType cameraType, CameraSensorLocation sensorLocation)
        {
            CameraConfig            cameraConfig       = null;
            PhotoCaptureDevice      photoCaptureDevice = null;
            FlashState              flash       = FlashState.Off;
            List <CameraResolution> resolutions = new List <CameraResolution>();

            try
            {
                // Read supported resolutions
                System.Collections.Generic.IReadOnlyList <Windows.Foundation.Size> SupportedResolutions =
                    PhotoCaptureDevice.GetAvailableCaptureResolutions(sensorLocation);
                resolutions = (from resolution in SupportedResolutions
                               select new CameraResolution
                {
                    Width = resolution.Width,
                    Height = resolution.Height
                }).ToList();

                // Read flash support.
                // Opening camera is required to read flash, request to open with min resolution
                var minResolution = SupportedResolutions.OrderBy(size => size.Width).First();
                photoCaptureDevice = await PhotoCaptureDevice.OpenAsync(sensorLocation, minResolution);

                Enum.TryParse <FlashState>(
                    photoCaptureDevice.GetProperty(KnownCameraPhotoProperties.FlashMode).ToString(),
                    true,
                    out flash);

                // Create the camera config
                cameraConfig = new CameraConfig
                {
                    Type  = (int)cameraType,
                    Sizes = resolutions,
                    Flash = flash != FlashState.Off ? true : false
                };
            }
            catch (Exception e)
            {
                Logger.Error("Error in Camera get configuration. Reason - " + e.Message);
            }
            finally
            {
                if (photoCaptureDevice != null)
                {
                    try { photoCaptureDevice.Dispose(); }
                    catch { }
                }
            }
            return(cameraConfig);
        }
예제 #6
0
        protected override void OnNavigatingFrom(NavigatingCancelEventArgs e) //当页面不再是框架中的活动页面时调用。
        {
            if (cam != null)
            {
                cam.Dispose();
                cam = null;
            }


            if (cam != null)
            {
                // Dispose camera to minimize power consumption and to expedite shutdown.
                cam.Dispose();

                // Release memory, ensure garbage collection.
                cam.PreviewFrameAvailable -= cam_PreviewFrameAvailable;
                //cam.Initialized -= cam_Initialized;
                //cam.CaptureCompleted -= cam_CaptureCompleted;
                //cam.CaptureImageAvailable -= cam_CaptureImageAvailable;
                //cam.CaptureThumbnailAvailable -= cam_CaptureThumbnailAvailable;
                //cam.AutoFocusCompleted -= cam_AutoFocusCompleted;
                //CameraButtons.ShutterKeyHalfPressed -= OnButtonHalfPress;
                //CameraButtons.ShutterKeyPressed -= OnButtonFullPress;
                //CameraButtons.ShutterKeyReleased -= OnButtonRelease;

                cam = null;
            }

            if (factory != null)
            {
                factory.Close();
                factory = null;
            }

            //timer.Stop();

            //PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Enabled;
        }
예제 #7
0
        /// <summary>
        /// If camera has not been initialized when navigating to this page, initialization
        /// will be started asynchronously in this method. Once initialization has been
        /// completed the camera will be set as a source to the VideoBrush element
        /// declared in XAML. On-screen controls are enabled when camera has been initialized.
        /// </summary>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (_photoCaptureDevice != null)
            {
                _photoCaptureDevice.Dispose();
                _photoCaptureDevice = null;
            }

            ShowProgress(AppResources.InitializingCameraText);
            await InitializeCamera(CameraSensorLocation.Back);

            HideProgress();
            BackgroundVideoBrush.SetSource(_photoCaptureDevice);

            SetScreenButtonsEnabled(true);
            SetCameraButtonsEnabled(true);
            Storyboard sb = (Storyboard)Resources["CaptureAnimation"];

            sb.Stop();

            SetOrientation(this.Orientation);

            base.OnNavigatedTo(e);
        }
예제 #8
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            NavigationContext.QueryString.TryGetValue("index", out _dateIndex);

            if (_photoCaptureDevice != null)
            {
                _photoCaptureDevice.Dispose();
                _photoCaptureDevice = null;
            }

            ProgressIndicator.IsRunning = true;
            SetScreenButtonsEnabled(false);
            SetCameraButtonsEnabled(false);

            await InitializeCamera(CameraSensorLocation.Back);

            BackgroundVideoBrush.SetSource(_photoCaptureDevice);

            ProgressIndicator.IsRunning = false;
            SetScreenButtonsEnabled(true);
            SetCameraButtonsEnabled(true);

            base.OnNavigatedTo(e);
        }
예제 #9
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;
        }
예제 #10
0
        protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
        {
            // If the camera was not initialize yet, the app does nothing to avoid crashes
            if (!this._isCameraInitialized)
            {
                e.Cancel = true;
                return;
            }

            if (PhotoCaptureDevice != null && !e.Uri.ToString().Contains("SettingsPage.xaml"))
            {
                PhotoCaptureDevice.Dispose();
                PhotoCaptureDevice = null;
            }

            SetScreenButtonsEnabled(false);
            SetCameraButtonsEnabled(false);

            base.OnNavigatingFrom(e);
        }
예제 #11
0
        protected virtual void Dispose(bool disposing)
        {
            IsDisposed = true;

            if (disposing)
            {
                // safe to access member object

                // make sure we dispose device, otherwise other app will not be able to use it
                if (_device != null /*&& !_capturing && !_focusing && !_barcodeDecoding*/)
                {
                    _device.Dispose();
                    _device = null;
                }

                // stop focus timer
                if (_focusTimer != null)
                {
                    if (_focusTimer.IsEnabled)
                    {
                        _focusTimer.Stop();
                    }
                    _focusTimer = null;
                }

                // stop barcode timer
                if (_barcodeTimer != null)
                {
                    if (_barcodeTimer.IsEnabled)
                    {
                        _barcodeTimer.Stop();
                    }
                    _barcodeTimer = null;
                }

                // events
                BarcodeDetected = null;
            }
        }