我正在构建一个使用相机的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对我来说还是一个新手。
非常感谢! 布雷特
答案 0 :(得分:4)
解决了: 我不得不添加一行:
<Capability Name="ID_CAP_ISV_CAMERA"/>
到我的WMAppManifent.xml
文件。