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

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 ...

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

Top White Papers and Webcasts

  • Hybrid cloud platforms need to think in terms of sweet spots when it comes to application platform interface (API) integration. Cloud Velocity has taken a unique approach to tight integration with the API sweet spot; enough to support the agility of physical and virtual apps, including multi-tier environments and databases, while reducing capital and operating costs. Read this case study to learn how a global-level Fortune 1000 company was able to deploy an entire 6+ TB Oracle eCommerce stack in Amazon Web …

  • "Security" is the number one issue holding business leaders back from the cloud. But does the reality match the perception? Keeping data close to home, on premises, makes business and IT leaders feel inherently more secure. But the truth is, cloud solutions can offer companies real, tangible security advantages. Before you assume that on-site is the only way to keep data safe, it's worth taking a comprehensive approach to evaluating risks. Doing so can lead to big benefits.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds