首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当我回到wp8的应用程序时,恢复相机吗?

当我回到wp8的应用程序时,恢复相机吗?
EN

Stack Overflow用户
提问于 2013-12-27 07:19:22
回答 1查看 89关注 0票数 0

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-27 07:38:24

好的,我在我的一个应用程序中也遇到了同样的问题,这个问题的发生是因为相机对象的实例没有被正确地刷新,而不正确的对象被重新分配到视频刷中,这使得事情以一种意想不到的方式发生。

要克服这个问题,你能做的最好的事情就是

用这几行代码重写OnNavigatedTo事件。

代码语言:javascript
复制
 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

代码语言:javascript
复制
        <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>

我希望能帮上忙

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20796558

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档