【问题标题】:Detecting Front and Back camera in windows 8 tabs在 Windows 8 选项卡中检测前置和后置摄像头
【发布时间】:2014-01-26 03:42:12
【问题描述】:

我正在使用 c# 和 xaml 开发 Metro 风格的应用程序。对于特定任务,我需要检测当前正在捕获哪个凸轮(正面或背面)。有没有办法在winrt中检测前凸轮或后凸轮。请帮帮我。

【问题讨论】:

    标签: windows-8 windows-runtime microsoft-metro windows-8.1


    【解决方案1】:

    您可以使用此代码。

     DeviceInformationCollection videoCaptureDevices = await eviceInformation.FindAllAsync(DeviceClass.VideoCapture);
    

    如果 videoCaptureDevices 计数为零,则表示未连接摄像头。
    如果摄像头数量是 2 ,那么就会有前后摄像头。

    如果您使用videoCaptureDevices [0] 初始化相机操作,则将使用前置摄像头,如果使用videoCaptureDevices [1],则将使用后置摄像头。

    【讨论】:

      【解决方案2】:

      在 DeviceInformationCollection 上使用索引不是可靠的解决方案:

      1. 有时前置摄像头的索引为 0,有时为 1,在表面 2 上测试几次后,它似乎有点随机。
      2. 用户可以使用 USB 端口连接其他网络摄像头,这样您最终可能会在收藏中获得超过 2 个项目,而无需知道哪个摄像头是哪个索引。

      遇到和你一样的问题,我就是这样解决的:

      // 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 网络摄像头大多数时候它似乎为空。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-28
        • 1970-01-01
        • 2013-01-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多