XAML C++ set Image Source()from SurfaceImageSource doesn't compile(fromlearn.microsoftexample)

fdbelqdn  于 2023-04-27  发布在  其他
关注(0)|答案(1)|浏览(94)

我尝试使用XAML Image重现Direct2D的SurfaceImageSource示例:
https://learn.microsoft.com/en-us/windows/uwp/gaming/directx-and-xaml-interop
我在这一行有一个编译错误:
theImage().Source(surfaceImageSource);
Source需要一个对ImageSource的引用,但是当我提供一个SurfaceImageSource时,它不会为我编译,就像示例中一样。
错误(活动)E0304没有重载函数“winrt::Microsoft::UI::Xaml::Controls::Image::Source”的示例与参数列表匹配
你知道可能出了什么问题吗?
最小代码:
在XML文件中:
<Image x:Name="theImage" Width="500" Height="500" />
在cpp文件上

void MainWindow::myButton_Click(IInspectable const&, RoutedEventArgs const&)
    {
        myButton().Content(box_value(L"Clicked"));

        SurfaceImageSource surfaceImageSource(500, 500);
        theImage().Source(surfaceImageSource); // -> FAIL here
    }
7z5jn7bk

7z5jn7bk1#

感谢Simon提供的有关WinUI3中使用的UWP示例的提示。以及开始帮助我但不完整的此链接:Exception thrown in SurfaceImageSource.as()
解决方案:
在pch.h中替换

#include <windows.ui.xaml.media.dxinterop.h>
#include <winrt/Windows.UI.Xaml.Media.Imaging.h>

通过

#include <windows.ui.xaml.media.dxinterop.h>
#include <winrt/Windows.UI.Xaml.Media.Imaging.h>

并在.cpp文件中替换:

using namespace Windows::UI::Xaml::Media::Imaging;

通过

using namespace Microsoft::UI::Xaml::Media::Imaging;

相关问题