【问题标题】:Display Image in Blank App (Universal Windows - C++/CX)在空白应用程序中显示图像(通用 Windows - C++/CX)
【发布时间】:2021-07-10 18:28:17
【问题描述】:

项目类型:

我的代码:

Image^ img = ref new Image();
img->Width = piece;
img->Height = piece;
Canvas::SetLeft(img, x * field + field / 2 - piece / 2);
Canvas::SetTop(img, y * field + field / 2 - piece / 2);
img->Source = ref new BitmapImage(ref new Uri("E:\\C++\\Assets\\Ball.png"));
csmain->Children->Append(img);

它不会显示存储在路径中的图像。图像甚至不可见。我没有任何线索。 我是 C++ 新手,但我非常了解 C#。

提前致谢:)

【问题讨论】:

标签: c++ image uwp c++-cx


【解决方案1】:

它不会显示存储在路径中的图像。图像甚至不可见。

UWP 平台无法直接显示带路径的图片。 (img->Source = ref new BitmapImage(ref new Uri("E:\\C++\\\\Assets\\Ball.png"));) 如果你想显示上述路径的图片文件,请使用文件选择器打开它,并将其转换为BitmapImage,或者使用windows storage api访问这个文件。前提是你需要开启broadFileSystemAccess能力。更多信息请参考document

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多