13,001,686 members (95,251 online)
Rate this:
See more:
The structure ICONINFO has two fields hbmMask & hbmColor. These fields are of type HIBITMAP.

I want to convert bitmap to icon. When I load bitmap file, bitmap handle HIBITMAP is returned. Using this, how can I get values for hbmMask & hbmColor which represent bitmask bitmap & color bitmap. If I set both filieds to HIBITMAP of the loaded bitmap, I get icon but without colors.

Can we extract the proper values for these fields from HIBITMAP?
Posted 2-Mar-11 19:58pm

Rate this:

## Solution 1

In the way you asked, no. Simply because an Icon is actually two bitmaps: an image (defines the color of the pixels) and a mask (defines which pixels have to be painted and which not, and hence be transparent).

An HBITMAP is just one image, so you cannot "extract" the other.
But you can "guess" it algorithmically. for example:

A) make the mask completly "black": all pixels will be drawn (no transparency)

B) look the pixel of the image an guess a color you may use as a "transparent color". Create a mask that is "white" where the image has that color. (if the image is a drawing, you can use the topleft pixel as "background color")

C) Same as B, but consider transparent also colors that are "close" under a given approximation to the chosen color.

A is trivial, B is simple (just require a BitBlt of a color image into a monochrome bitmap) C requires more parsing of the picture.
Niklas Lindquist 3-Mar-11 17:09pm

Voted 5.
In addition to C. One can look at the hue of the color to determine if the color at a given pixel is 'close enough' to a reference value.

Top Experts
Last 24hrsThis month
 OriginalGriff 290 ppolymorphe 180 Bohdan Stupak 115 F-ES Sitecore 110 Dave Kreskowiak 60
 OriginalGriff 4,857 ppolymorphe 2,437 RickZeeland 2,221 Kornfeld Eliyahu Peter 2,031 Richard Deeming 1,643