Search code examples
c#wpfstreamiconsnotifyicon

Getting Icon from ResourceStream


I have a Icon.ico and in the Properties the Build Action is "Resource"...

I want to load that Icon in the Application..

I did something like this:

Icon theIcon = new Icon(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MyNameSpace.Icon.ico"));

that didnt worked (it says "Value of 'null' is not valid for 'stream'.")

What can I do?


Solution

  • try using Application.GetResourceStream method

    using(Stream stream = Application.GetResourceStream(new Uri("/MyNameSpace.ico")).Stream)
    {
        Icon myIcon = new System.Drawing.Icon(stream);
    }
    

    more information from MSDN