我正在使用USB 3.0相机来显示它的预览屏幕。但似乎Windows不承认它是成像设备所以当我尝试打开Windows 10的Camera应用程序默认时,它显示错误。 所以我的问题是如何将USB 3.0相机作为我们可以在UWP中使用的成像设备?
答案 0 :(得分:0)
不确定我是否正确理解了这个问题。
首先,您应该在应用的清单中启用相机/网络摄像头功能。
然后试试这个:
MediaCapture _mediaCapture = new MediaCapture();
var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
DeviceInformation deviceInfo = devices.FirstOrDefault();
if (deviceInfo == null)
deviceInfo = devices.ElementAtOrDefault(0);
var settings = new MediaCaptureInitializationSettings()
{
VideoDeviceId = deviceInfo?.Id,
PhotoCaptureSource = PhotoCaptureSource.Auto,
StreamingCaptureMode = StreamingCaptureMode.Video,
};
if (deviceInfo == null)
_mediaCapture = null;
if (_mediaCapture != null)
{
await _mediaCapture.InitializeAsync(settings);
await _mediaCapture.StartPreviewAsync();
}
修改强>
如果它不起作用且devices
不包含您需要的相机,您应该尝试通过设备ID / guid手动找到您的设备:
// by (vendorid, deviceid)
string aqs = Windows.Devices.Usb.UsbDevice.GetDeviceSelector(0x1234, 0xabcd);
// or by device GUID
string aqs = Windows.Devices.Usb.UsbDevice.GetDeviceSelector(new Guid("camera guid"));
当你得到aqs
时:
var myDevices = await DeviceInformation.FindAllAsync(aqs);
UsbDevice usbDevice = await Windows.Devices.Usb.UsbDevice.FromIdAsync(myDevices[0].Id);
// or try init MediaCaptureInitializationSettings
var settings = new MediaCaptureInitializationSettings()
{
VideoDeviceId = myDevices.FirstOrDefault()?.Id,
PhotoCaptureSource = PhotoCaptureSource.Auto,
StreamingCaptureMode = StreamingCaptureMode.Video,
};