我正在开发一个地铁风格的应用程序使用c#和xaml。对于特定的任务,我需要检测哪个摄像头(前置或后置)当前正在捕获。在winrt中有没有办法检测前置摄像头或后置摄像头?请帮帮我。
发布于 2014-08-13 19:00:36
在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的工作原理相同。
只需查看每个枚举的.EnclosureLocation.Panel属性,它就是一个Windows.Devices.Enumeration.Panel DeviceInformation。剩下的部分,前面是前置摄像头,后面是后置摄像头。
也要小心检查.EnclosureLocation是否为空,使用USB网络摄像头大多数时候似乎都是空的。
发布于 2014-01-10 14:05:57
您可以使用此代码。
DeviceInformationCollection videoCaptureDevices = await eviceInformation.FindAllAsync(DeviceClass.VideoCapture);如果videoCaptureDevices计数为零,则没有连接摄像头。
如果相机数量是2,那么将有两个前置和后置相机。
如果使用videoCaptureDevices [0]初始化相机操作,则将使用前置相机,如果使用videoCaptureDevices [1],则将使用后置相机。
https://stackoverflow.com/questions/20988887
复制相似问题