从ResourceStream获取图标

eMi*_*eMi 3 c# wpf icons stream notifyicon

我有一个Icon.ico,在属性中,Build Action是"Resource"...

我想在应用程序中加载该图标..

我做了这样的事情:

Icon theIcon = new Icon(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MyNameSpace.Icon.ico"));
Run Code Online (Sandbox Code Playgroud)

没有用(它说'null'的值对'stream'无效.")

我能做什么?

Dam*_*ith 6

尝试使用Application.GetResourceStream方法

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

来自MSDN的更多信息