简体   繁体   English

Windows Phone 8中的Camera App中的NotSupportedException

[英]NotSupportedException in Camera App in Windows Phone 8

I am working on Windows Phone 8,since I am new on this technology, I need a help regarding camera. 我正在使用Windows Phone 8,因为我是这项技术的新手,所以我需要有关相机的帮助。 I am working on camera test, I got a NotSupportedException (Specified Method not Supported) kind of exception on back key press event. 我正在进行相机测试,在返回键按下事件时遇到了NotSupportedException (不支持指定方法)类异常。 If I pressed back key immediately after initialization of camera then it will crash the application. 如果我在初始化相机后立即按了返回键,则它将使应用程序崩溃。 I didn't get any source related with this issue. 我没有任何与此问题相关的消息来源。 so, can anyone help me to figure out this problem ? 所以,有人可以帮我解决这个问题吗?

Thanks 谢谢

Xaml for your page, might be like this 您网页的Xml可能是这样

        <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>

Cs Code Cs代码

protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            base.OnBackKeyPress(e);
//make some navigation like this
                    NavigationService.Navigate(new Uri("/View/EditDocument.xaml, UriKind.RelativeOrAbsolute));
        }

   protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            try
            {
                InitializeCamera(); 
            }
            catch (Exception ex)
            {
                MessageBox.Show("Problem occured in camera declaration.");
            }
       }

        public void InitializeCamera()
        {
            try
            {
                if (myCamera != null)
                {
                    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;
                canvasCameraView.Background = null;
                myCamera = null;
                bdrInitializingCamera.Visibility = Visibility.Visible;
                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);
            }
            catch (Exception ex)
            {
                if (MessageBox.Show("An error occured in camera initialization, please try again. note \n " + ex.Message) == MessageBoxResult.OK)
                {
                   //Make a navigation
                }
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM