简体   繁体   中英

UWP Camera preview size issue

I have an issue with my UWP application. I want to preview camera using 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. 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. Does anybody have an idea, how can I fix it? 在此处输入图片说明

Edit: Here ii a code, which I use to initialize MediaCapture and start preview:

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. It seems that you need to set the DisplayInformation.AutoRotationPreferences property to DisplayOrientations.Landscape . This will change preferred orientation of the app and it makes the preview bigger if there is enough place for the CaptureElement

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM