public void Dispose() { if (_cameraCaptureDevice != null) { _cameraCaptureDevice.Dispose(); } if (_mediaLibrary != null) { _mediaLibrary.Dispose(); } SaveSettings(); }
private void ShutDownCamera() { if (Camera != null) { Camera.Dispose(); Camera = null; } }
private void UninitializeCamera() { if (_device != null) { _device.PreviewFrameAvailable -= PhotoCaptureDevice_PreviewFrameAvailable; _device.Dispose(); _device = null; } }
/// <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; }
// 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); }
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; }
/// <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); }
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); }
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; }
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); }
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; } }