首页 > 解决方案 > NoesisGUI - 在 Noesis.Image 元素中加载 PNG

问题描述

我在将 png 图像分配给 XAML 中的 Image 元素时遇到了麻烦。在运行时应用程序崩溃异常:

InvalidCastException:无法将“System.Drawing.Bitmap”类型的对象转换为“System.Byte []”类型。

我的步骤如下:

  1. 应用程序.xaml.cs

    protected override TextureProvider GetTextureProvider() { EmbeddedTexture[] textures = { new EmbeddedTexture {filename="icon.png", resource="icon"}, new EmbeddedTexture {filename="download.jpg", resource="download"} }; return new EmbeddedTextureProvider(textures, Properties.Resources.ResourceManager); }

  2. 主窗口.xaml

<Image Source="icon.png"/>

  1. 我使用构建操作“资源”在项目目录中添加了 icon.png,并在 Resources.resx 文件中添加了相同的内容。

我从 Github 运行了 Menu3D 示例,它毫无问题地加载了 png 图像。有人可以指出我可能做错了什么吗?我会很感激帮助。谢谢。

标签: c#desktop-application

解决方案


我在他们的论坛上发布了这个问题并在这里找到了解决方法:

http://www.noesisengine.com/forums/viewtopic.php?f=3&t=1404

解决方法是编辑 Resources.resx 文件并将每个图像文件的“System.Drawing.Bitmap, System.Drawing”替换为“System.Byte[], mscorlib”。还要更改 Resources.Designer.cs 中的 getter,并将“Bitmap”类型替换为“Byte[]”类型。


推荐阅读