Windows Phone 8中的Camera App中的NotSupportedException

时间:2013-12-30 10:48:47

标签: windows-phone-8

我正在使用Windows Phone 8,因为我是这项技术的新手,我需要有关相机的帮助。我正在进行相机测试,我在后退按键事件上得到了NotSupportedException(指定的方法不支持)类型的异常。如果我在相机初始化后立即按下键,那么它将使应用程序崩溃。我没有得到与此问题相关的任何来源。 那么,任何人都可以帮我解决这个问题吗?

由于

1 个答案:

答案 0 :(得分:0)

您网页的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>

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