UWP相机预览尺寸问题

时间:2018-02-13 18:19:45

标签: c# windows visual-studio camera uwp

我的UWP应用程序存在问题。我想使用MediaCapture预览相机。当我在笔记本电脑上使用这个应用程序时,一切都运行正常,预览很好,预览的大小还可以,但是当我在我的Lumia 950上使用这个应用程序时,预览真的很小。当我使用后置摄像头时它非常糟糕,前置摄像头显示更大的预览。在下面的图片中你可以看到,在我的Lumia上我只得到了这个小小的相机预览而且也不清楚,因为焦点不起作用。有没有人有想法,我该如何解决? enter image description here

编辑:这里是一个代码,用于初始化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();

1 个答案:

答案 0 :(得分:2)

我比较了将显示预览的官方样本CameraStartKit 使用您的代码段进行大规模处理。您似乎需要将DisplayInformation.AutoRotationPreferences属性设置为DisplayOrientations.Landscape。这将改变应用程序的首选方向,如果CaptureElement

有足够的位置,它会使预览更大