【发布时间】:2014-01-26 03:42:12
【问题描述】:
我正在使用 c# 和 xaml 开发 Metro 风格的应用程序。对于特定任务,我需要检测当前正在捕获哪个凸轮(正面或背面)。有没有办法在winrt中检测前凸轮或后凸轮。请帮帮我。
【问题讨论】:
标签: windows-8 windows-runtime microsoft-metro windows-8.1
我正在使用 c# 和 xaml 开发 Metro 风格的应用程序。对于特定任务,我需要检测当前正在捕获哪个凸轮(正面或背面)。有没有办法在winrt中检测前凸轮或后凸轮。请帮帮我。
【问题讨论】:
标签: windows-8 windows-runtime microsoft-metro windows-8.1
您可以使用此代码。
DeviceInformationCollection videoCaptureDevices = await eviceInformation.FindAllAsync(DeviceClass.VideoCapture);
如果 videoCaptureDevices 计数为零,则表示未连接摄像头。
如果摄像头数量是 2 ,那么就会有前后摄像头。
如果您使用videoCaptureDevices [0] 初始化相机操作,则将使用前置摄像头,如果使用videoCaptureDevices [1],则将使用后置摄像头。
【讨论】:
在 DeviceInformationCollection 上使用索引不是可靠的解决方案:
遇到和你一样的问题,我就是这样解决的:
// Still need to find all webcams
DeviceInformationCollection webcamList = await eviceInformation.FindAllAsync(DeviceClass.VideoCapture)
// Then I do a query to find the front webcam
DeviceInformation frontWebcam = (from webcam in webcamList
where webcam.EnclosureLocation != null
&& webcam.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front
select webcam).FirstOrDefault();
// Same for the back webcam
DeviceInformation backWebcam = (from webcam in webcamList
where webcam.EnclosureLocation != null
&& webcam.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back
select webcam).FirstOrDefault();
在此示例中,我使用了 Linq 查询,但它与“webcamList”上的 foreach 相同。
只需查看每个 DeviceInformation 的 .EnclosureLocation.Panel 属性,它是一个 Windows.Devices.Enumeration.Panel 枚举。剩下的就很明显了,Front 是前置摄像头,Back 是后置摄像头。
还要仔细检查 .EnclosureLocation 是否为空,使用 USB 网络摄像头大多数时候它似乎为空。
【讨论】: