Hi
How can I extract a image of specific size or all images from an Icon with multiple images?
TIA and best regards
Hi
How can I extract a image of specific size or all images from an Icon with multiple images?
TIA and best regards
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 theSM_CXICON
,SM_CYICON
,SM_CXSMICON
, andSM_CYSMICON
flags to find out the dimensions of each type.