在Windows 10通用应用程序中使用isTypePresent如何检测相机是否可用 [英] How to detect is a camera is available using isTypePresent in a Windows 10 Universal Application

查看:192
本文介绍了在Windows 10通用应用程序中使用isTypePresent如何检测相机是否可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在为Windows 10开发通用应用程序时,建议您使用 IsTypePresent 检测设备特定的硬件.(Microsoft将此功能称为'示例,用于检查设备的背面按钮是:

When developing a Universal Application for Windows 10 you are encouraged to detect device specific hardware using IsTypePresent. (Microsoft refer to this feature as 'Light up'). An example from the documentation that checks for a device's back button is:

<代码>if(Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))Windows.Phone.UI.Input.HardwareButtons.BackPressed + = HardwareButtons_BackPressed;

在这里很明显,字符串"Windows.Phone.UI.Input.HardwareButtons" 作为参数传递给 IsTypePresent()方法.

It is clear here that the string "Windows.Phone.UI.Input.HardwareButtons" is passed as an argument to the IsTypePresent() method.

我想知道是否有一种简单的方法来识别可用于其他硬件,尤其是相机的其他字符串.

I would like to know if there is an easy way to identify other strings that I could use for other pieces of hardware and, in particular, the camera.

推荐答案

IsTypePresent不是用于检测硬件存在,而是用于检测API存在.在您的代码段中,它正在检查是否存在供应用程序调用的HardwareButtons类,而不是设备是否具有硬件按钮(在这种情况下,它们可能会在一起,但这不是IsTypePresent所寻找的).

IsTypePresent isn't used to detect hardware presence but to detect API presence. In your code snippet it's checking if the HardwareButtons class exists for the app to call, not if the device has hardware buttons (in this case they're likely to go together, but that's not what IsTypePresent is looking for).

与相机一起使用的MediaCapture类是Universal API Contract的一部分,因此始终存在并且可以调用.如果没有适当的音频或视频设备,初始化将失败.

The MediaCapture class used with the camera is part of the Universal API Contract and so is always there and callable. Initialization will fail if there is no appropriate audio or video device.

要查找硬件设备,可以使用Windows.Devices.Enumeration命名空间.这是一个快速片段,可查询相机并找到第一个的ID.

To find hardware devices you can use the Windows.Devices.Enumeration namespace. Here's a quick snippet that queries for cameras and finds the ID of the first one.

var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);

if (devices.Count < 1)
{
    // There is no camera. Real code should do something smart here.
    return;
}

// Default to the first device we found
// We could look at properties like EnclosureLocation or Name
// if we wanted a specific camera
string deviceID = devices[0].Id;

// Go do something with that device, like start capturing!

这篇关于在Windows 10通用应用程序中使用isTypePresent如何检测相机是否可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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