Windows 8 在windows 8选项卡中检测前后摄像头
我正在使用c#和xaml开发一个metro风格的应用程序。对于特定任务,我需要检测当前正在捕获的cam(前或后)。在winrt中是否有检测前凸轮或后凸轮的方法。请帮助我。您可以使用此代码Windows 8 在windows 8选项卡中检测前后摄像头,windows-8,windows-runtime,microsoft-metro,windows-8.1,Windows 8,Windows Runtime,Microsoft Metro,Windows 8.1,我正在使用c#和xaml开发一个metro风格的应用程序。对于特定任务,我需要检测当前正在捕获的cam(前或后)。在winrt中是否有检测前凸轮或后凸轮的方法。请帮助我。您可以使用此代码 DeviceInformationCollection videoCaptureDevices = await eviceInformation.FindAllAsync(DeviceClass.VideoCapture); 如果videoCaptureDevices计数为零,则表示未连接摄像头。 如果摄像
DeviceInformationCollection videoCaptureDevices = await eviceInformation.FindAllAsync(DeviceClass.VideoCapture);
如果videoCaptureDevices计数为零,则表示未连接摄像头。如果摄像头数量为2,则前后摄像头都会出现
如果您使用
videoCaptureDevices[0]
初始化相机操作,则将使用前置相机,如果使用videoCaptureDevices[1]
,则使用设备信息收集上的索引将不会是可靠的解决方案:
// 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上也可以使用相同的方法
只需查看每个设备信息.EnclosureLocation.Panel属性,它是一个Windows.Devices.Enumeration.Panel枚举。其余的是obvius,前面是前置摄像头,后面是后置摄像头
也要小心检查.EnclosureLocation是否为空,使用USB网络摄像头,大多数情况下它似乎为空