[VB] [UWP]使用后置摄像头使用MediaCapture拍摄照片 [英] [VB][UWP]Using the back camera to take a photo using MediaCapture

查看:103
本文介绍了[VB] [UWP]使用后置摄像头使用MediaCapture拍摄照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用后置摄像头和后置摄像头。 MediaCapture预览并在UWP应用中拍照。这是我目前的代码:

I want to use the back camera & MediaCapture to preview and take a photo in a UWP app. Here is my current code:

Me.mc = New MediaCapture()
Dim backcamera As DeviceInformation = (Await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture)).FirstOrDefault(Function(cameras) cameras.EnclosureLocation.Panel = Global.Windows.Devices.Enumeration.Panel.Back)
Await Me.mc.InitializeAsync(New MediaCaptureInitializationSettings() With {.VideoDeviceId = backcamera.Id,
   .MemoryPreference = MediaCaptureMemoryPreference.Cpu,
   .SharingMode = MediaCaptureSharingMode.ExclusiveControl,
   .StreamingCaptureMode = StreamingCaptureMode.Video,
   .PhotoCaptureSource = PhotoCaptureSource.VideoPreview})
Await Me.mc.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, Me.mc.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview).Cast(Of VideoEncodingProperties).Where(Function(vec) vec.Width / vec.Height = 1)(0))

在这段代码中,我收到了fo在最后一行(我称之为SetMediaStreamPropertiesAsync的那一行)上发光:

In this code, I receive the following on the last line (the one where I call SetMediaStreamPropertiesAsync):

System.ArgumentException

System.ArgumentException

价值不会下降在预期的范围内。

此代码在我的Surface Book i7上工作正常,但在Surface Pro上给了我这个错误。我对使用相机和相机有点新手媒体,所以修复可能相当简单,但我不确切知道如何。我基本上想要做的是允许用户预付&b
使用MediaCapture拍摄照片,我希望照片是正方形(不是风景或肖像)。
我需要更改什么才能使代码适用于所有设备?谢谢。

This code worked fine on my Surface Book i7, but gives me this error on my Surface Pro. I am somewhat new to working with cameras & media, so this is probably reasonably simple to fix, but I don't know exactly how. What I basically want to do is allow the user to preview & capture a photo using MediaCapture, and I want the photo to be square (not landscape or portrait). What do I need to change to make the code work with all devices? Thanks.

Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

推荐答案

您应该调试以查看导致问题的设置。我的水晶球说你的Surface Pro后置摄像头不支持方形宽高比,所以试图强制失败。而是使用可用的矩形纵横比,然后在之后裁剪
You should debug to see which setting is causing the problem. My crystal ball says that your Surface Pro's back camera doesn't support the square aspect ratio so trying to force that fails. Instead use an available rectangular aspect ratio and then crop it afterwards.


这篇关于[VB] [UWP]使用后置摄像头使用MediaCapture拍摄照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆