Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Win32 VC10.0
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 20:58pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

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.
  Permalink  
Comments
Niklas Lindquist at 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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 3 Mar 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100