在为 Windows 10 开发通用应用程序时,建议您使用 IsTypePresent
检测设备特定的硬件.(微软将此功能称为 '点亮').检查设备背面的文档示例按钮是:
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:
<代码>如果(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 类是通用 API 契约的一部分,因此始终存在且可调用.如果没有合适的音频或视频设备,初始化将失败.
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 检测相机是否可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!