如何从图标中提取特定尺寸的图像?

发布于 2024-09-24 22:31:49 字数 35 浏览 0 评论 0原文

如何从具有多个图像的图标中提取特定尺寸的图像或所有图像?

How can I extract an image of a specific size or all images from an icon with multiple images?

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

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

发布评论

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

评论(1

想念有你 2024-10-01 22:31:49

您没有说明这样做的目的是什么,并且有多种获取图标的方法,并且根据目的,一种方法可能比另一种方法更好。

但是,要从任意文件中提取任意数量的“大”(32x32) 和/或“小”(16x16) 图标*,请使用 ExtractIconEx 函数。这使您可以从图标文件 (.ico)、EXE 或 DLL 中提取这两种标准尺寸之一的一个或多个图标。一个图标文件可以包含多个图像,此功能可以让您获取所有图像。

该函数将写入句柄数组,您可以将每个句柄分配给 TIcon 实例的 Handle 属性。然后您可以像平常一样使用 TIcon 方法如果您以其他方式加载 TIcon,则会出现这种情况。请注意,Delphi XE 的新功能是能够通过分配将其轻松复制到位图方法那篇文章还展示了如何访问所有库存(内置/标准)Windows 图标,如果这恰好是您想要的。

(旁注:我认为 TIcon 类让您通过其 LoadFromFile 方法从文件加载 - 文档中似乎缺少该方法,但我很确定它存在,从记忆中,它只加载一个图标。)

(*) 其实“大”和“小”都可以
与 32x32 和 16x16 不同:使用

GetSystemMetrics
SM_CXICON 一起使用的函数,
SM_CYICONSM_CXSMICON
SM_CYSMICON 标志来找出
每种类型的尺寸。

You don't say what the purpose of this is, and there are a number of ways of getting icons and one method may be better than another depending on the purpose.

However, to extract any number of "large" (32x32) and/or "small" (16x16) icons* from an arbitrary file, use the ExtractIconEx function. This lets you extract one or more icons of either of these two standard sizes from an icon file (.ico), EXE, or DLL. An icon file can contain multiple images and this function will let you get all of them.

The function will write to an array of handles, each of which you can assign to the Handle property of a TIcon instance. Then you can use the TIcon methods as you normally would if you'd loaded the TIcon any other way. Note that new to Delphi XE is the ability to copy it easily to a bitmap via the Assign method. That article also shows how to access all of the stock (inbuilt / standard) Windows icons, if that happens to be what you're after.

(Side note: I think the TIcon class lets you load from a file via its LoadFromFile method - this seems to be missing from the documentation, but I'm pretty certain it exists. From memory, that only loads a single icon.)

(*) Actually, "large" and "small" can
be different to 32x32 and 16x16: use
the
GetSystemMetrics
function with the SM_CXICON,
SM_CYICON, SM_CXSMICON, and
SM_CYSMICON flags to find out the
dimensions of each type.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文