2012-05-14 29 views
0

我正在构建使用相机的Windows Phone应用程序。我的代码:Windows Phone - 访问相机需要ISV相机功能

private void MainPage_Loaded(object sender, RoutedEventArgs e) 
{ 

if ((PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true) || 
    (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing) == true)) { 
    // Initialize the default camera. 
    _photoCamera = new Microsoft.Devices.PhotoCamera(); 

    //Event is fired when the PhotoCamera object has been initialized 
    _photoCamera.Initialized += new EventHandler<Microsoft.Devices.CameraOperationCompletedEventArgs>(OnPhotoCameraInitialized); 

     //Set the VideoBrush source to the camera 
     viewfinderBrush.SetSource(_photoCamera); 
    } 
    else { 
     // The camera is not supported on the device. 
     this.Dispatcher.BeginInvoke(delegate() { 
     // Write message. 
      txtDebug.Text = "A Camera is not available on this device."; 
     }); 

    } 

} 

private void OnPhotoCameraInitialized(object sender, CameraOperationCompletedEventArgs e) { 
    int width = Convert.ToInt32(_photoCamera.PreviewResolution.Width); 
    int height = Convert.ToInt32(_photoCamera.PreviewResolution.Height); 
} 

而且我不断收到异常:“访问摄像头需要ISV相机能力”

我有一个Lumia 900,我知道它运行相机APIs(样品表格MS工作正常)。但是当我把这段代码放到我的应用程序中时,我得到了这个异常。有谁知道可能会发生什么?我是一个好的C#'呃,但Windows Phone对我来说是相当新的。

非常感谢! 布雷特

回答

4

解决它: 我不得不行补充:

<Capability Name="ID_CAP_ISV_CAMERA"/> 

WMAppManifent.xml文件。