通过位图的索引号从CImageList中获取CBitmap位图对象的函数如下:
//CImageList中获取CBitmap位图对象
void GetListImage(CImageList &ImageList, CBitmap &Bitmap, int nImageIdx)
{
CClientDC dcClient(NULL);
IMAGEINFO ImageInfo;
ImageList.GetImageInfo(nImageIdx, &ImageInfo);
int nWidth = abs(ImageInfo.rcImage.right - ImageInfo.rcImage.left);
int nHeight = abs(ImageInfo.rcImage.bottom - ImageInfo.rcImage.top);
Bitmap.CreateCompatibleBitmap(&dcClient, nWidth, nHeight);
CDC dcMemory;
dcMemory.CreateCompatibleDC((CDC*)NULL) ;
CBitmap * pBmpOld = dcMemory.SelectObject(&Bitmap);
dcMemory.FillSolidRect(0, 0, nWidth, nHeight, RGB(255,255,255));
ImageList.Draw(&dcMemory, nImageIdx, CPoint(0,0), ILD_NORMAL);
dcMemory.SelectObject(pBmpOld);
dcMemory.DeleteDC();
::DeleteObject( ImageInfo.hbmImage );
::DeleteObject( ImageInfo.hbmMask );
}
调用方法:
CBitmap bitmap;
GetListImage(m_ImageList, bitmap, 0); //第一个位图
然后通过CDC的BitBlt(或者StretchBlt、TransparentBlt)绘制到界面上,效果如图: