如何从 Vista/7 可执行文件中提取完整图标?

发布于 2024-08-19 23:28:20 字数 546 浏览 1 评论 0原文

如果我有一个 Vista .ico 文件,其中包含 16x16、32x32、256x256 等版本的图标,我可以通过简单地执行以下操作成功地将其加载为 .NET 图标:

Icon myIcon = new Icon("C:\\MyIcon.ico");

然后我可以访问图标。我什至可以使用详细的方法访问 256x256 Vista PNG 此处

但是,我还没有找到从 Vista 可执行文件中获取全套图标图像的方法。不幸的是,这样做 -:

Icon myIcon = Icon.ExtractAssociatedIcon("C:\\MyExe.exe");

...只会导致提取单个 32x32 图像。有没有办法从可执行文件中获取整组图像作为 .NET 图标?最好是也能在 XP 下运行的一个。

If I have a Vista .ico file which contains a 16x16, 32x32, 256x256 etc. version of an icon, I can successfully load it as a .NET Icon by simply doing -:

Icon myIcon = new Icon("C:\\MyIcon.ico");

I can then access all of the various sized images in the icon. I can even access the 256x256 Vista PNG using methods detailed HERE.

However, I haven't found a way to get the full set of icon images from a Vista executable. Unfortunately, doing this -:

Icon myIcon = Icon.ExtractAssociatedIcon("C:\\MyExe.exe");

...only results in a single 32x32 image being extracted. Is there a way get the entire set of images from an executable as a .NET Icon? Preferably one that also works in XP.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对你的占有欲 2024-08-26 23:28:20

使用 PrivateExtractIcons API 尝试此代码片段:

[DllImport("User32.dll", CharSet = CharSet.Auto)]
      internal static extern UInt32 PrivateExtractIcons(String lpszFile, int nIconIndex, int cxIcon, int cyIcon, IntPtr[] phicon, IntPtr[] piconid, UInt32 nIcons, UInt32 flags);

IntPtr[] phicon = new IntPtr[] { IntPtr.Zero };
IntPtr[] piconid = new IntPtr[] { IntPtr.Zero };

PrivateExtractIcons(path, 0, cx, cy, phicon, piconid, 1, 0);

if (phicon[0] != IntPtr.Zero)
    return System.Drawing.Icon.FromHandle(phicon[0]);

try this snippet with PrivateExtractIcons API:

[DllImport("User32.dll", CharSet = CharSet.Auto)]
      internal static extern UInt32 PrivateExtractIcons(String lpszFile, int nIconIndex, int cxIcon, int cyIcon, IntPtr[] phicon, IntPtr[] piconid, UInt32 nIcons, UInt32 flags);

IntPtr[] phicon = new IntPtr[] { IntPtr.Zero };
IntPtr[] piconid = new IntPtr[] { IntPtr.Zero };

PrivateExtractIcons(path, 0, cx, cy, phicon, piconid, 1, 0);

if (phicon[0] != IntPtr.Zero)
    return System.Drawing.Icon.FromHandle(phicon[0]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文