开发者

How can I extract an image of a specific size from an icon?

开发者 https://www.devze.com 2023-01-18 03:03 出处:网络
How can I extra开发者_开发百科ct an image of a specific size or all images from an icon with multiple images?You don\'t say what the purpose of this is, and there are a number of ways of getting icons

How can I extra开发者_开发百科ct an image of a specific size or all images from an icon with multiple images?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消