我是windows phone 8应用程序开发人员,我的问题是如何恢复摄像头?基本上,相机是我的应用程序的第一页,当我切换到电话中的其他功能时,当我回到应用程序时,相机页面就变黑了。
发布于 2013-12-27 07:38:24
好的,我在我的一个应用程序中也遇到了同样的问题,这个问题的发生是因为相机对象的实例没有被正确地刷新,而不正确的对象被重新分配到视频刷中,这使得事情以一种意想不到的方式发生。
要克服这个问题,你能做的最好的事情就是
用这几行代码重写OnNavigatedTo事件。
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
if (myCamera != null) // myCamera=PhotoCamera Object
{
//Unsubscribing the events
myCamera.AutoFocusCompleted -= OnCameraAutoFocusCompleted;
myCamera.Initialized -= myCamera_Initialized;
myCamera.CaptureCompleted -= new EventHandler<CameraOperationCompletedEventArgs>(camera_CaptureCompleted);
myCamera.CaptureImageAvailable -= new EventHandler<Microsoft.Devices.ContentReadyEventArgs>(camera_CaptureImageAvailable);
}
viewfinderBrush = null;//viewfinderBrush =VideoBrush Onject
canvasCameraView.Background = null; //canvasCameraView=Canvas Control I Used
myCamera = null;
viewfinderBrush = new VideoBrush();
CompositeTransform ct = new CompositeTransform();
ct.CenterX = .5;
ct.CenterY = .5;
ct.Rotation = 90;
viewfinderBrush.RelativeTransform = ct;
canvasCameraView.Background = viewfinderBrush;
myCamera = new Microsoft.Devices.PhotoCamera(CameraType.Primary);
viewfinderBrush.SetSource(myCamera);
myCamera.Initialized += myCamera_Initialized;
myCamera.CaptureCompleted += new EventHandler<CameraOperationCompletedEventArgs>(camera_CaptureCompleted);
myCamera.CaptureImageAvailable += new EventHandler<Microsoft.Devices.ContentReadyEventArgs>(camera_CaptureImageAvailable);
}这是xaml
<Canvas.Background>
<VideoBrush x:Name="viewfinderBrush">
<VideoBrush.RelativeTransform>
<CompositeTransform x:Name="viewfinderBrushTransform" CenterX=".5" CenterY=".5" Rotation="90" />
</VideoBrush.RelativeTransform>
</VideoBrush>
</Canvas.Background>
<StackPanel Name="stkLoading" Height="50" Canvas.Top="245" Visibility="Collapsed">
<TextBlock Foreground="Red" Text="Scanning.." HorizontalAlignment="Center"/>
<ProgressBar IsIndeterminate="True" Width="480"/>
</StackPanel>
</Canvas>我希望能帮上忙
https://stackoverflow.com/questions/20796558
复制相似问题