c# - NoesisGUI - 在 Noesis.Image 元素中加载 PNG
问题描述
我在将 png 图像分配给 XAML 中的 Image 元素时遇到了麻烦。在运行时应用程序崩溃异常:
InvalidCastException:无法将“System.Drawing.Bitmap”类型的对象转换为“System.Byte []”类型。
我的步骤如下:
应用程序.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); }
主窗口.xaml
<Image Source="icon.png"/>
- 我使用构建操作“资源”在项目目录中添加了 icon.png,并在 Resources.resx 文件中添加了相同的内容。
我从 Github 运行了 Menu3D 示例,它毫无问题地加载了 png 图像。有人可以指出我可能做错了什么吗?我会很感激帮助。谢谢。
解决方案
我在他们的论坛上发布了这个问题并在这里找到了解决方法:
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[]”类型。
推荐阅读
- python - 如何查找元素列表是否在另一个元素列表中?
- laravel - 当 CommandFinished 事件触发时,Laravel 捕获字符串输出
- r - 在 NA 值之后读取带有未指定尾随空格的 csv
- php - php cURL请求后没有来自API的回调
- reactjs - 我应该在哪里以及如何在我的 Create React App 中添加 JSON-LD 模式?
- python-3.x - 如何在 GCP 的作曲家中读取从云函数传递到 Dataproc SparkOperator 的参数
- angular - Angular - 导入 BrowserAnimationsModule 和 NoopAnimationsModule 并决定在运行时使用什么(使用 AOT)
- sql - 从 SQL Server 表中查找和删除重复行
- javascript - 来自响应数据的 javascript 映射
- python - 慢熊猫索引查找唯一索引