我是windows phone 8 app开发者,我的问题是如何恢复相机?基本上相机是我的应用程序的第一页,当我切换到手机中的一些其他功能,当我回到应用程序,然后相机页面变黑。
答案 0 :(得分:0)
好吧,我在我的一个应用程序中也遇到了同样的问题,出现这个问题是因为photocamera对象的实例没有正确刷新,并且不正确的对象被重新分配给视频画笔,这使得事情进展顺利一种意想不到的方式。
你能解决这个问题的最佳方法是
使用这些代码行重写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>
我希望它有所帮助