[英]UWP Camera preview size issue
I have an issue with my UWP application. 我的UWP应用程序有问题。 I want to preview camera using MediaCapture.
我想使用MediaCapture预览相机。 Everything is working fine when I am using this app on my laptop, preview is nice and size of the preview is ok, but when I use this application on my Lumia 950, preview is just really small.
当我在笔记本电脑上使用此应用程序时,一切正常,预览效果很好,并且预览尺寸还可以,但是当我在Lumia 950上使用此应用程序时,预览效果确实很小。 When I use rear camera it is really bad, front camera shows a little bit bigger preview.
当我使用后置摄像头时,这真的很糟糕,前置摄像头会显示更大的预览。 In the picture below you can see, that on my Lumia I get only this little camera preview and it is also not clear, because focus does not work.
在下面的图片中,您可以看到,在我的Lumia上,我仅获得了此小巧的相机预览,并且它也不清晰,因为对焦不起作用。 Does anybody have an idea, how can I fix it?
有人有想法,我该如何解决?
Edit: Here ii a code, which I use to initialize MediaCapture and start preview: 编辑:这是我用来初始化MediaCapture并开始预览的代码:
private MediaCapture mediaCapture = new MediaCapture();
var cameras = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
if (cameras.Count < 1)
{
Error.Text = "No camera found, decoding static image";
await DecodeStaticResource();
return;
}
MediaCaptureInitializationSettings settings = null;
if (cameras.Count == 1)
{
settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameras[0].Id, StreamingCaptureMode = StreamingCaptureMode.Video };
changeCamera.Visibility = Visibility.Collapsed;
}
else
{
int camID = (int) localSettings.Values["camID"];
settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameras[camID].Id, StreamingCaptureMode = StreamingCaptureMode.Video }; // 0 => back, 1 => front
}
await mediaCapture.InitializeAsync(settings);
if (cameras.Count != 1)
{
if (localSettings.Values["camID"].ToString() == "0")
{
mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
}
else if(localSettings.Values["camID"].ToString() == "1")
{
mediaCapture.SetPreviewRotation(VideoRotation.Clockwise270Degrees);
}
}
VideoCapture.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();
I compared the Official sample CameraStartKit which will display the preview in a large size with your code snippet. 我比较了官方示例CameraStartKit ,它将以您的代码段大尺寸显示预览。 It seems that you need to set the
DisplayInformation.AutoRotationPreferences
property to DisplayOrientations.Landscape
. 似乎您需要将
DisplayInformation.AutoRotationPreferences
属性设置为DisplayOrientations.Landscape
。 This will change preferred orientation of the app and it makes the preview bigger if there is enough place for the CaptureElement
如果有足够的位置放置
CaptureElement
这将更改应用程序的首选方向,并使预览更大
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.