gpt4 book ai didi

c# - 如何在 Windows 10 通用应用程序中使用 isTypePresent 检测相机是否可用

转载 作者:可可西里 更新时间:2023-11-01 13:28:57 26 4
gpt4 key购买 nike

在为 Windows 10 开发通用应用程序时,我们鼓励您使用 IsTypePresent 检测特定于设备的硬件。 (Microsoft 将此功能称为“Light up”)。一个example from the documentation检查设备后退按钮的是:


如果(Windows.Foundation.Metadata.ApiInformation.IsTypePresent(“Windows.Phone.UI.Input.HardwareButtons”))
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;

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

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

最佳答案

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

与相机一起使用的 MediaCapture 类是通用 API 契约的一部分,因此始终存在且可调用。如果没有合适的音频或视频设备,初始化将失败。

要查找硬件设备,您可以使用 Windows.Devices.Enumeration 命名空间。下面是一个快速片段,用于查询摄像头并找到第一个摄像头的 ID。

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!

关于c# - 如何在 Windows 10 通用应用程序中使用 isTypePresent 检测相机是否可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30809094/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com