我正在尝试制作一个游戏(通用 DX11 应用程序),在某些时候我需要访问图像库以允许用户选择头像。但由于某种原因,在选择器上调用 PickSingleFileAsync 会引发异常。
Windows::Storage::Pickers::FileOpenPicker^ openPicker = ref new Windows::Storage::Pickers::FileOpenPicker();
openPicker->SuggestedStartLocation = Windows::Storage::Pickers::PickerLocationId::PicturesLibrary;
openPicker->ViewMode = Windows::Storage::Pickers::PickerViewMode::Thumbnail;
// Filter to include a sample subset of file types.
auto filters = openPicker->FileTypeFilter;
filters->Clear();
filters->Append(".png");
openPicker->PickSingleFileAsync();// same exception with create_task(...);
似乎该示例仅在我将其放入 UI 线程中时才有效。我如何从我自己的线程中使用选择器?
更新:HRESULT:0x80004005
好吧,我只是决定调用dipatcher的RunAsync来执行这段代码。但我仍然不知道为什么我无法在非 UI 线程内打开选取器。
您是否在提升模式下运行应用程序? 如果应用程序以管理员权限启动,则此 api 无法工作。