Friday, June 07, 2013

CImageList reduces 24-bit bitmaps to 16 colors

Lots of people have complained that their 256-color bitmaps are reduced to 16 colors in an ImageList. But the same thing happened to me with a true-color bitmap. The solution is the same; create the image list and load bitmap as separate steps:
// 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);
Another thing that was a "gotcha" for me: CImageList actually modifies any bitmap you add to it, changing all "transparent color" pixels to black.

Finally a third "gotcha" is that you must use the ILC_MASK flag when you create the image list. Without this flag, the image list still changes all "transparent color" pixels to black (which is a preparation step for using mask-based transparency), but doesn't actually generate the mask, which causes ILD_TRANSPARENT and ILD_NORMAL modes to not work.

2 Comments:

At 4/09/2014 12:59 AM, Anonymous App development services said...

This blog is really awesome

 
At 4/15/2014 2:14 AM, Anonymous join us said...

this blog is really awesome

 

Post a Comment

<< Home