Windows Phone - 访问相机需要 ISV 相机功能

本文关键字:相机 ISV 功能 Windows 访问 Phone | 更新日期: 2023-09-27 18:34:04

我正在构建一个使用相机的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对我来说是相当新的。

非常感谢!布雷特

Windows Phone - 访问相机需要 ISV 相机功能

解决了:我不得不添加以下行:

<Capability Name="ID_CAP_ISV_CAMERA"/>

到我的WMAppManifent.xml文件。