0

我正在构建一个使用相机的 Windows Phone 应用程序。我有代码:

 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

1 回答 1

4

解决了:我必须添加以下行:

<Capability Name="ID_CAP_ISV_CAMERA"/>

到我的WMAppManifent.xml档案。

于 2012-05-14T18:42:30.513 回答