我可以从进程中获取可执行文件的位置,如何从文件中获取图标?
也许可以使用Windows API LoadIcon()。我想知道是否有.NET的方法...
我可以从进程中获取可执行文件的位置,如何从文件中获取图标?
也许可以使用Windows API LoadIcon()。我想知道是否有.NET的方法...
Icon ico = Icon.ExtractAssociatedIcon(theProcess.MainModule.FileName);
这是一个控制台应用程序实现的示例。
using System;
using System.Drawing; //For Icon
using System.Reflection; //For Assembly
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
try
{
//Gets the icon associated with the currently executing assembly
//(or pass a different file path and name for a different executable)
Icon appIcon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
}
catch(ArgumentException ae)
{
//handle
}
}
}
}
Icon = Icon.ExtractAssociatedIcon(Process.GetCurrentProcess().MainModule.FileName);
代替反射当前程序集,会更快吗? - Igor Levicki编辑:我进行了快速的 SO 搜索,并发现 这里。索引 0 图标是应用程序图标。