-
- SannanKhan
- Posts: 3
- Joined:
NoesisGUI For C# Desktop Application Development
I am having troubles assigning a png image to Image element in XAML. At runtime the application crashes with exception
1. App.xaml.cs
2. MainWindow.xaml
3. I added icon.png in project dir with build action "Resource" and added the same in Resources.resx file.
I ran the Menu3D sample from Github which loaded png images without any trouble. Can someone please point out what I might be doing wrong? I'd appreciate the help.
Thanks.
My steps are as follows:InvalidCastException: Unable to cast object of type 'System.Drawing.Bitmap' to type 'System.Byte[]'.
1. App.xaml.cs
Code: Select all
protected override TextureProvider GetTextureProvider()
{
EmbeddedTexture[] textures =
{
new EmbeddedTexture {filename="icon.png", resource="icon"}
};
return new EmbeddedTextureProvider(textures, Properties.Resources.ResourceManager);
}
Code: Select all
<Image Source="icon.png"/>
I ran the Menu3D sample from Github which loaded png images without any trouble. Can someone please point out what I might be doing wrong? I'd appreciate the help.
Thanks.
Re: NoesisGUI For C# Desktop Application Development
Hi, I got this problem too, I solved it by changing "System.Drawing.Bitmap, System.Drawing" with "System.Byte[], mscorlib" in the Resources.resx file for each image. I also modified the getters in Resources.Designer.cs. That's a workaround but if someone have a better solution I'll take it!
-
- SannanKhan
- Posts: 3
- Joined:
Re: NoesisGUI For C# Desktop Application Development
That solved my problem! Thank you so much Cleik.Hi, I got this problem too, I solved it by changing "System.Drawing.Bitmap, System.Drawing" with "System.Byte[], mscorlib" in the Resources.resx file for each image. I also modified the getters in Resources.Designer.cs. That's a workaround but if someone have a better solution I'll take it!

-
-
sfernandez
Site Admin
- Posts: 2107
- Joined:
Re: NoesisGUI For C# Desktop Application Development
There is no direct way to change how an image resource is stored in the Resources.resx through Visual Studio interface (a combo box for selecting the resource Type in the resource properties, as it occurs with text files, would have been great).
So the unique and correct way I found to change it is right click on Resources.resx 'View Code' and modify the type in the xml definition:
Once you rebuild the project, Resources.Designer.cs getters and setters for the image resources will be updated accordingly.
So the unique and correct way I found to change it is right click on Resources.resx 'View Code' and modify the type in the xml definition:
Code: Select all
<data name="BackgroundImage" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\BackgroundImage.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
Re: NoesisGUI For C# Desktop Application Development
Remember, this is the way we decided to pack our resources in our samples. But you don't need to do it that way, you can reimplement the providers and return Stream to your content. For example, just a provider that opens files from disk should be trivial to implement.
Who is online
Users browsing this forum: No registered users and 0 guests