Question

I am developing an MFC application. I am working with my own .bmp image with Visual Studio. I import bmp via the add resource dialog, give it a unique name and create a CImageList. I am then setting the image list in a list control:

CListCtrl m_CIDList;
CImageList m_ImgList;

//.........

m_ImgList.Create(IDB_MYBITMAP, 15, 0, RGB(255, 255, 255));
m_CIDList.SetImageList(&m_ImgList, LVSIL_STATE);

The problem I am having is strange. Only certain colors will show up, usually only red and grey. I have tried using different Bit Depths, but that has changed nothing. Here is what the bmp looks like in the image editor in VS:

BMP image in editor

When the icons are displayed in the list control, only a few of the reds are showing up and all of the green shows up as grey.

I am not quite sure what is going on, does anybody have an idea of what is happening?

Solution Update

m_ImgList.Create(15, 15, ILC_MASK | ILC_COLOR24, 0, 0);
CBitmap bmp;
bmp.LoadBitmap(IDB_MYBITMAP);
m_ImgList.Add(&bmp, RGB(255, 255, 255));
m_CIDList.SetImageList(&m_ImgList, LVSIL_STATE);
Was it helpful?

Solution

When the image list is created and no color value is given, the default color mode is ILC_COLOR4 which only allows 16 predefined colors for the image. All of the colors in your bitmap are being mapped to those 16 colors.

Use ILC_COLOR24 for full color bitmaps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top