[英]How can I get the icon from the executable file only having an instance of it's Process in C#
I can get the executable location from the process, how do I get the icon from file? 我可以从进程中获取可执行文件位置,如何从文件中获取图标?
Maybe use windows api LoadIcon(). 也许使用windows api LoadIcon()。 I wonder if there is .NET way...
我想知道是否有.NET方式......
Icon ico = Icon.ExtractAssociatedIcon(theProcess.MainModule.FileName);
This is a sample from a console application implementation. 这是来自控制台应用程序实现的示例。
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
}
}
}
}
Use the ExtractIconEx (and here ) p/invoke. 使用ExtractIconEx (和此处 )p / invoke。 You can extract small and large icons from any dll or exe.
您可以从任何DLL或exe中提取小图标和大图标。 Shell32.dll itself has over 200 icons that are quite useful for a standard Windows application.
Shell32.dll本身有200多个图标,对标准Windows应用程序非常有用。 You just have to first figure out what the index is for the icon(s) you want.
您只需先弄清楚所需图标的索引是什么。
Edit: I did quick SO search and found this . 编辑:我做了快速SO搜索,发现了这一点 。 The index 0 icon is the application icon.
索引0图标是应用程序图标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.