c#图标提取
1个回答
展开全部
这个是源码:是在一个窗体中拖入一个exe文件可以获取,你可以修改一下 [DllImport("Shell32.dll")]//引入"Shell32.dll" private static extern int SHGetFileInfo(string pszPath, uint dwFileAttributes, out SHFILEINFO psfi, uint cbfileInfo, SHGFI uFlags); [StructLayout(LayoutKind.Sequential)] struct SHFILEINFO { public IntPtr hIcon; public int iIcon; public uint attributes; [MarshalAs(UnmanagedType.LPStr, SizeConst = 260)] public string szDisplayName; [MarshalAs(UnmanagedType.LPStr, SizeConst = 80)] public string szTypeName; public SHFILEINFO(bool b) { hIcon = IntPtr.Zero; iIcon = 0; attributes = 0; szDisplayName = ""; szTypeName = ""; } } private enum SHGFI { SmallIcon = 0x00000001, LargeIcon = 0x00000020, Icon = 0x00000100, DisplayName = 0x00000200, TypeName = 0x00000400, SysIconIndex = 0x00004000, UseFileAttributes = 0x00000010 } public static Icon GetIcon(string path, bool small) { SHFILEINFO info = new SHFILEINFO(true); int cbFileInfo = Marshal.SizeOf(info); SHGFI flags; if (small) { flags = SHGFI.Icon | SHGFI.SmallIcon | SHGFI.UseFileAttributes; } else { flags = SHGFI.Icon | SHGFI.LargeIcon | SHGFI.UseFileAttributes; } SHGetFileInfo(path, 256, out info, (uint)cbFileInfo, flags); return Icon.FromHandle(info.hIcon); }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询