Loading an 8bpp (256 color) Bitmap Into an ImageList As a 32bpp Bitmap


Application Security Testing: An Integral Part of DevOps

Environment: MFC, Win32

One thing that always bugged me about ImageLists is that when you load a 256 color bitmap into them, they use the half-tone pallette, which likely could screw up your bitmap's colors. Yet, Windows Explorer is magically able to display icons in it's right pane list control (coming from an ImageList) in full color. So how does it do this?


  BOOL CImageList::Create( UINT nBitmapID,
                           int cx,
                           int nGrow,
                           COLORREF crMask)
  BOOL CImageList::Create( LPCTSTR lpszBitmapID, 
                           int cx,
                           int nGrow,
                           COLORREF crMask)
  HIMAGELIST ImageList_LoadBitmap( HINSTANCE hi,
                                   LPCTSTR lpbmp,
                                   int cx,
                                   int cGrow,
                                   COLORREF crMask)
                                LPCSTR lpbmp,
                                int cx,
                                int cGrow,
                                COLORREF crMask,
                                UINT uType,
                                UINT uFlags)

None of the above methods will do the trick. They will use the half-tone pallette, since they seem to detect the 8bpp nature of the bitmap and create an "ILC_COLOR8" ImageList, and ImageLists with the ILC_COLOR8 flag always use the half-tone pallette.

To get around this, you can create the ImageList in one step and then add the bitmap in a second step. In the below examples, I assume that you will be using a COLORREF mask for transparency - but nothing requires this to be the case; you could just as easily use a mask bitmap. The key to this technique is the two-step construction and loading of the ImageList.



// Create the full-color image list
// cx, cy = your icon width & height
// You could also use ILC_COLOR24 rather than ILC_COLOR32
CImageList imgl;
imgl.Create(cx, cy, ILC_MASK | ILC_COLOR32, 0, 0);

CBitmap bmp;
// Load your imagelist bitmap (bmp) here, however 
//   you feel like (e.g. CBitmap::LoadBitmap)

COLORREF rgbTransparentColor;
// Set up your transparent color as appropriate

// Add the bitmap into the image list
imgl.Add(&bmp, rgbTransparentColor);


// Create the full-color image list
// cx, cy = your icon width & height
// You could also use ILC_COLOR24 rather than ILC_COLOR32
HIMAGELIST himgl = ImageList_Create(cx, 
                                    ILC_MASK | ILC_COLOR32,

// Load your imagelist bitmap (hbmp) here, however
//    you feel like (e.g. LoadImage)

COLORREF rgbTransparentColor;
// Set up your transparent color as appropriate

// Add the bitmap into the image list
ImageList_AddMasked(himgl, hbmp, rgbTransparentColor);


  • image

    Posted by Legacy on 02/02/2004 12:00am

    Originally posted by: priya

    how to take image(any jpeg,bmp,etc) as input in c language program

  • Which Lib File must need?

    Posted by Legacy on 09/23/2003 12:00am

    Originally posted by: Sukhyun

    In My Project, linker unresolved external symbol __imp__ImageList_LoadImageA@28.
    Which Library I must import in this project?

  • How to read an image from *.pdf, *.jpg, *.bmp files

    Posted by Legacy on 06/06/2003 12:00am

    Originally posted by: Muhammad Faisal ali

    How to read an image from *.pdf, *.jpg, *.bmp files. I wanna take some guidence about this regards please help me as soon as possible voluntarily. I never forget your help.

  • control checkboxes

    Posted by Legacy on 05/20/2003 12:00am

    Originally posted by: Mihaela

    how can i control the checkboxes assigned to an item from an ImageList: for modify their size, position and apereance

  • Still no happy

    Posted by Legacy on 03/26/2003 12:00am

    Originally posted by: joghurt

    This still doesn't work for me. It still screws up colors and won't make the propers mask. (Win2000 and XP)

    I did a simple test: a bitmap with the standard 16 Windows colors. Then added it to the image list with various colours as the transparent colour. For RGB(0,0,0) the colours were completely broken. If the transparent colour had been RGB (255,0,0), RGB (0,255,0), RGB (0,0,255) or RGB (0,128,128), ImageList_AddMasked was simply unable to generate the proper mask. However, for values RGB(255,255,0), RGB(255,0,255), RGB(0,255,255), RGB(128,128,128), RGB(192,192,192) and RGB(255,255,255) it was as it should be.

    By the way, according to Microsoft,
    "Bitmaps with color depth greater than 8bpp are not supported" for ImageList_AddMasked.

    Any comments/ideas?

  • how to add the image to the resource ?

    Posted by Legacy on 01/06/2003 12:00am

    Originally posted by: shangxiaolei

    Thank you guy, but I don't know how to get the nBitmap's ID.Could somebody tell me.I will be very thankful.

  • How to loading an 8bpp (256 color) Bitmap File Into an ImageList As a 32bpp Bitmap

    Posted by Legacy on 12/28/2002 12:00am

    Originally posted by: marfos

    .help i need more color in my life

  • Aligning Image on a Button

    Posted by Legacy on 12/23/2002 12:00am

    Originally posted by: Vipin Singh

    How can we align a image on a button. We are creating imagelist and then adding images to it using ImageList_AddMasked and then sending the message to add the buttons using SendMessage. But the images are rightaligned on the button. Does any one has idea how can we left align or center align a image on the button. This is urgent. Pls. reply asap and pls. copy replies to my ID also.


  • Excellent work, but why?

    Posted by Legacy on 10/19/2002 12:00am

    Originally posted by: Michael

    Why we should do this in 2 step?

  • thanks

    Posted by Legacy on 10/15/2002 12:00am

    Originally posted by: gengyf

    it help me in time! thanks very much!

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.