如何从图标中提取特定尺寸的图像?
如何从具有多个图像的图标中提取特定尺寸的图像或所有图像?
How can I extract an image of a specific size or all images from an icon with multiple images?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有说明这样做的目的是什么,并且有多种获取图标的方法,并且根据目的,一种方法可能比另一种方法更好。
但是,要从任意文件中提取任意数量的“大”(32x32) 和/或“小”(16x16) 图标*,请使用
ExtractIconEx
函数。这使您可以从图标文件 (.ico)、EXE 或 DLL 中提取这两种标准尺寸之一的一个或多个图标。一个图标文件可以包含多个图像,此功能可以让您获取所有图像。该函数将写入句柄数组,您可以将每个句柄分配给
TIcon
实例的Handle
属性。然后您可以像平常一样使用TIcon
方法如果您以其他方式加载 TIcon,则会出现这种情况。请注意,Delphi XE 的新功能是能够通过分配将其轻松复制到位图方法。 那篇文章还展示了如何访问所有库存(内置/标准)Windows 图标,如果这恰好是您想要的。(旁注:我认为
TIcon
类让您通过其LoadFromFile
方法从文件加载 - 文档中似乎缺少该方法,但我很确定它存在,从记忆中,它只加载一个图标。)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 aTIcon
instance. Then you can use theTIcon
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 itsLoadFromFile
method - this seems to be missing from the documentation, but I'm pretty certain it exists. From memory, that only loads a single icon.)