嵌入式资源文件的路径

我的资源文件中有一个图标,我想引用它。

这是需要该图标文件路径的代码:

IWshRuntimeLibrary.IWshShortcut MyShortcut ; MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\PerfectUpload.lnk"); MyShortcut.IconLocation = //path to icons path . Works if set to @"c:/icon.ico" 

我没有外部图标文件,而是希望它找到嵌入式图标文件。 就像是

 MyShortcut.IconLocation = Path.GetFullPath(global::perfectupload.Properties.Resources.finish_perfect1.ToString()) ; 

这可能吗 ? 如果是这样的话?

谢谢

我认为它可以帮助你…

 //Get the assembly. System.Reflection.Assembly CurrAssembly = System.Reflection.Assembly.LoadFrom(System.Windows.Forms.Application.ExecutablePath); //Gets the image from Images Folder. System.IO.Stream stream = CurrAssembly.GetManifestResourceStream("ImageURL"); if (null != stream) { //Fetch image from stream. MyShortcut.IconLocation = System.Drawing.Image.FromStream(stream); } 

我认为这应该有效,但我记不清楚了(不用再仔细检查)。

 MyShortcut.IconLocation = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("YourNamespace.IconFilename.ico"); 

只是扩展SharpUrBrain的答案 ,这对我不起作用,而不是:

 if (null != stream) { //Fetch image from stream. MyShortcut.IconLocation = System.Drawing.Image.FromStream(stream); } 

它应该是这样的:

 if (null != stream) { string temp = Path.GetTempFileName(); System.Drawing.Image.FromStream(stream).Save(temp); shortcut.IconLocation = temp; } 

res协议可能能够帮助您: http : //msdn.microsoft.com/en-us/library/aa767740(v = vs。85).aspx

在WPF中我之前做过:

 Uri TweetyUri = new Uri(@"/Resources/MyIco.ico", UriKind.Relative); System.IO.Stream IconStream = Application.GetResourceStream(TweetyUri).Stream; NotifyIcon.Icon = new System.Drawing.Icon(IconStream); 

它嵌入的资源,因此封装在DLL程序集中。 因此,你不能得到真正的道路,你必须改变你的方法。

您可能希望将资源加载到内存中并将其写入临时文件,然后从那里链接它。 在目标文件上更改图标后,您可以删除图标文件本身。