Delphi Shell IExtractIcon usage and result Delphi Shell IExtractIcon usage and result shell shell

Delphi Shell IExtractIcon usage and result


Take your 256x256 bitmap and simply check for alpha. Make sure the bmp is 32bits. Any part that has 0 for the pixel value (that is BGRA 0,0,0,0, use TBitmap.Scanline to access) is transparent. You can find the smallest x and smallest y coord that has a nonzero value and that's the actual size of your icon. Now, this number may be smaller than the "icon size" as it was designed. For instance, a 16x16 icon can contain an image of 2x2, which would be a weird design.

But of course an 8x16 icon is very well possible. Considering the images are always square, take the max if the x and y coordinates found (with and height of actual image) and round it up to the nearest of 16,24,32,48,64,128 or 256. You can be quite certain that you'll have the icon centered in your bitmap if you crop to this size next. Use Bmp.Width=sz; Bmp.Height=sz;.You could then scale it up, or center it onto your standard bitmap (56x56? 256x256?).

So, even if windows doesn't feel like giving you the right info, you can bypass the need for this info by simply finding out yourself. This may not be the "correct" way to do it, but you'll know that it'll work when you're done, as opposed to browsing MSDN for 4 hours and never finding an answer.