[英]How to display the current camera resolution on screen
我试图在屏幕上显示当前的摄像机分辨率,以便用户知道当前的分辨率,并在需要时随时进行调整。 在我的应用程序中,所有相机功能都可以使用,但是由于某种原因,每当我尝试访问当前相机分辨率并将其显示在文本框中时,都会收到UnauthorizedAccessException。 我尝试查询OnNavigatedTo事件和camera_Initialized事件中的分辨率值。 我在做什么错,我如何更改当前的实现方式才能正常工作?
MainPage.xaml.cs
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if ((PhotoCamera.IsCameraTypeSupported(CameraType.Primary) == true) ||
(PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing) == true))
{
// Initialize the camera, when available.
if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
{
// Use front-facing camera if available.
camera = new PhotoCamera(CameraType.Primary);
camera.Initialized += camera_Initialized;
viewfinderBrush.SetSource(camera);
//display current resolution
resolutionValueTextBlock.Text = "resolution: " + camera.Resolution.ToString(); //UnauthorizedAccessException occurs here
}
}
...
}
void camera_Initialized(object sender, CameraOperationCompletedEventArgs e)
{
if (e.Succeeded)
{
if (Settings.firstRun.Value)
{
//Set highest camera resolution on first run and by default
Size resolution = camera.AvailableResolutions.OrderByDescending(s => s.Width).First();
camera.Resolution = resolution;
//display current resolution
resolutionValueTextBlock.Text = "resolution: " + camera.Resolution.ToString(); //UnauthorizedAccessException
...
}
else
{
Size resolution = camera.AvailableResolutions.ElementAt(Settings.tempResolutionIndex.Value);
camera.Resolution = resolution;
//display current resolution
resolutionValueTextBlock.Text = "resolution: " + camera.Resolution.ToString(); //UnauthorizedAccessException
}
}
}
由于您尝试在UI上显示某些内容,因此需要使用Dispatcher进行显示。
Deployment.Current.Dispatcher.BeginInvoke( ()=> { resolutionValueTextBlock.Text = "resolution: " + camera.Resolution.ToString(); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.