花了三四天才搞定,记录下,供有需要的人参考
//
// Initialize media capture with the source group.
//
_mediaCapture = ref new Windows::Media::Capture::MediaCapture();
auto settings = ref new Windows::Media::Capture::MediaCaptureInitializationSettings();
//
// Select the source we will be reading from.
//
settings->SourceGroup = group; =======> 怎么找media group需要自己去研究了
//
// This media capture can share streaming with other apps.
//
// For HL1
if (_deviceType == DeviceType::HL1)
{
settings->SharingMode =
Windows::Media::Capture::MediaCaptureSharingMode::SharedReadOnly;
}
// For HL2
if (_deviceType == DeviceType::HL2)
{
settings->SharingMode =
Windows::Media::Capture::MediaCaptureSharingMode::ExclusiveControl;
}
//
// Only stream video and don't initialize audio capture devices.
//
settings->StreamingCaptureMode =
Windows::Media::Capture::StreamingCaptureMode::Video;
//
// Set to CPU to ensure frames always contain CPU SoftwareBitmap images,
// instead of preferring GPU D3DSurface images.
//
settings->MemoryPreference =
Windows::Media::Capture::MediaCaptureMemoryPreference::Cpu;
//
// Only stream video and don't initialize audio capture devices.
//
settings->StreamingCaptureMode = Windows::Media::Capture::StreamingCaptureMode::Video;
// HL2默认分辨率896 * 504,这里改成1280 * 760 提高二维码识别率
// https://learn.microsoft.com/en-us/windows/mixed-reality/develop/advanced-concepts/locatable-camera-overview ==》 官网对profile的说明
dbg::trace(L"MediaFrameSourceGroup::TryInitializeMediaCaptureAsync: MediaCaptureVideoProfileMediaDescription begin.");
Windows::Foundation::Collections::IVectorView<Windows::Media::Capture::MediaCaptureVideoProfile^>^ profileList = _mediaCapture->FindAllVideoProfiles(group->Id);
for (Windows::Media::Capture::MediaCaptureVideoProfile^ profile : profileList)
{
bool found = false;
for (Windows::Media::Capture::MediaCaptureVideoProfileMediaDescription^ desc : profile->SupportedPhotoMediaDescription)
{
if ((desc->Height == 720) && (desc->Width == 1280) && (desc->FrameRate == 15))
{
settings->VideoProfile = profile;
settings->RecordMediaDescription = desc;
found = true;
dbg::trace(L"!!!!MediaCaptureVideoProfileMediaDescription found .");
break;
}
}
if (found == true)
break;
}
//
// Initialize MediaCapture with the specified group.
// This must occur on the UI thread because some device families
// (such as Xbox) will prompt the user to grant consent for the
// app to access cameras.
// This can raise an exception if the source no longer exists,
// or if the source could not be initialized.
//
return Concurrency::create_task(
_mediaCapture->InitializeAsync(settings)) ====》设置生效
.then([this](Concurrency::task<void> initializeMediaCaptureTask)
{