我正在開發使用PhotoCamera
捕獲圖像的windows phone 8應用程序。當我按屏幕鎖定鍵時出現問題。當我按下鎖定鍵時,我的PhotoCamera
物體不處理。當我在Camera Initialization
時按屏幕鎖鍵時,我遇到問題。初始化時發生PhotoCamera問題
這是一些代碼。
按鈕點擊代碼
_photoCamera = new PhotoCamera();
_photoCamera.Initialized += OnPhotoCameraInitialized;
_photoCamera.CaptureImageAvailable += new EventHandler<Microsoft.Devices.ContentReadyEventArgs>(cam_CaptureImageAvailable);
_photoCamera.AutoFocusCompleted += new EventHandler<CameraOperationCompletedEventArgs>(cam_AutoFocusCompleted);
_previewTransform.Rotation = _photoCamera.Orientation;
_previewVideo.SetSource(_photoCamera);
這裏是我的OnPhotoCameraInitialized代碼
private void OnPhotoCameraInitialized(object sender, CameraOperationCompletedEventArgs e)
{
try
{
Dispatcher.BeginInvoke(() =>
{
gvCamera.Visibility = Visibility.Visible;
gvCameraImage.Visibility = Visibility.Collapsed;
Cancel.Visibility = Visibility.Visible;
imgScanCancle.Visibility = Visibility.Visible;
});
cameraInit = true;
_photoCamera.FlashMode = FlashMode.Auto;
_photoCamera.Focus();
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message);
}
}
這裏是我的NavigationFrom代碼
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
try
{
if (cameraInit)
{
if (_photoCamera != null)
{
_photoCamera.Dispose();
_photoCamera.Initialized -= OnPhotoCameraInitialized;
_photoCamera.CaptureImageAvailable -= cam_CaptureImageAvailable;
_photoCamera.AutoFocusCompleted -= cam_AutoFocusCompleted;
_photoCamera = null;
cameraInit = false;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
我在的OnNavigatedTo方法
這裏是的OnNavigatedTo代碼重新初始化photocamera。
if (GlobalSettings.IspreservedState)
{
if (!GlobalSettings.istest_performed)
{
if (_photoCamera == null)
{
_nbTry = 0;
_photoCamera = new PhotoCamera();
_photoCamera.Initialized += OnPhotoCameraInitialized;
_photoCamera.CaptureImageAvailable += new EventHandler<Microsoft.Devices.ContentReadyEventArgs>(cam_CaptureImageAvailable);
_photoCamera.AutoFocusCompleted += new EventHandler<CameraOperationCompletedEventArgs>(cam_AutoFocusCompleted);
_previewTransform.Rotation = _photoCamera.Orientation;
_previewVideo.SetSource(_photoCamera);
}
}
}
基本上我想要做的是捕獲圖片並顯示它。在照相機初始化之前按下鎖定鍵時出現問題。當我按下鎖定鍵時,OnNavigatedFrom代碼開始執行。當達到if(cameraInit)
內部代碼不執行時,因爲cameraInit
不正確。我在OnPhotoCameraInitialized方法中設置了cameraInit = true;
。但不幸的是這個代碼塊沒有執行。所以我的問題是如何處理相機對象?只有當它完全初始化時,我才能處置它。但是我在Initialization
之前按下了鎖定鍵。有什麼方法可以清潔視頻畫筆嗎?