javascript - 当我回到 wp8 中的应用程序时恢复相机?

标签 javascript asp.net-mvc html css windows-phone-7

我是 Windows Phone 8 应用程序开发人员,我的问题是如何恢复摄像头?基本上相机是我应用程序的第一页,当我切换到手机中的某些其他功能时,当我返回应用程序时,相机页面变黑了。

最佳答案

好吧,我在我的一个应用程序中也遇到了同样的问题,这个问题的发生是因为 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>

希望对你有帮助

关于javascript - 当我回到 wp8 中的应用程序时恢复相机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20796558/

相关文章:

asp.net - ASP.NET 中 Google API 中的 redirect_uri_mismatch

javascript - 使用 window.scrollY 进行 Canvas 计算会导致问题

javascript - javascript中的c()函数是什么意思?

jquery - 收到回复后无法更改按钮文本

javascript - 如何使用 momentjs 格式化格式化字符串

javascript - 如果输入找到打开的容器,否则什么都不做

javascript - 无法在 <canvas> 中保存图像

javascript - 如何在node.js中同步运行这个函数

asp.net-mvc - 如何在受密码保护的 asp.net-mvc 站点上自动调用 url

c# - 对于 mvc 4 的文本框,空字符串返回 null