我正在嘗試使用自動對焦功能編寫基本相機應用程序以處理條形碼。如果我按照相機聚焦的方式向後按,則會進入空白屏幕並掛在那裏 - 不會拋出異常。我已經將問題追溯到CaptureImage()方法,我可以看到它被調用,但是從不調用OnCaptureImageAvailable方法。即使我沒有解開OnNavigatedFrom方法中的OnCaptureImageAvailable,也會發生這種情況。如果在拍照時按下背面,WP7相機CaptureImage不會返回
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
_camera.AutoFocusCompleted -= OnCameraAutoFocusCompleted;
_camera.CaptureImageAvailable -= OnCaptureImageAvailable;
_camera.Initialized -= OnCameraInitialized;
_camera.Dispose();
_camera = null;
}
private void InitializeCamera()
{
_camera = new PhotoCamera();
_camera.Initialized += OnCameraInitialized;
viewfinderBrush.SetSource(_camera);
}
void OnCameraInitialized(object sender, EventArgs e)
{
_camera.Initialized -= OnCameraInitialized;
_camera.AutoFocusCompleted += OnCameraAutoFocusCompleted;
_camera.CaptureImageAvailable += OnCaptureImageAvailable;
_camera.FlashMode = FlashMode.Off;
_camera.Focus();
}
private void OnCameraAutoFocusCompleted(object sender, EventArgs e)
{
_camera.CaptureImage();
}
private void OnCaptureImageAvailable(object sender, ContentReadyEventArgs e)
{
if (_camera != null && e.ImageStream != null)
ScanBarcode(e);
}
如果我刪除OnNavigateFrom中的_camera.Dispose(),它將返回調用頁面,但無法再打開此頁面。似乎相機尚未準備好進行初始化。我已經在這裏上傳了這個項目:'https:// github.com/cobusbernard/CameraIssue /'來說明問題。 – 2012-04-20 09:29:37