将图象列表转换成设备无关位图
不简单了.我试着将图象列表转换成DIB,但是我真正需要的是一个方法,能够取出一
个ICON的DIB,而不是整个图象列表。下面就是我使用的具体方法:
HANDLE CAdvancedTreeCtrl::ImageToDIB( CImageList* pImageList, int iImageNumber, CWnd* pWnd, BOOL bOverlay, HTREEITEM actualItem )
{
// Local Variables
CBitmap bitmap;
CWindowDCdc( pWnd );
CDC memDC;
CRectrect;
CPalette pal;
IMAGEINFO imageInfo;
if( FALSE == pImageList->GetImageInfo( iImageNumber, &imageInfo ) )
{
// Getting of the Imageinfos failed
return NULL;
}
// Create compatible stuff and select Bitmap
if( FALSE == memDC.CreateCompatibleDC( &dc ) )
{
// Create failed
return NULL;
}
if( FALSE == bitmap.CreateCompatibleBitmap( &dc,
imageInfo.rcImage.bottom-imageInfo.rcImage.top,
imageInfo.rcImage.right-imageInfo.rcImage.left ) )
{
// Create failed
return NULL;
}
CBitmap* pOldBitmap = memDC.SelectObject( &bitmap );
if( NULL == pOldBitmap )
{
// Select failed
return NULL;
}
// Local Variables for Draw
CPoint point( 0, 0);
UINT nStyle = ILD_NORMAL;
// Is there an Overlay
if( TRUE == bOverlay )
{
TV_ITEM tv_item;
// Set up the Item-Struct
tv_item.hItem = actualItem;
// Get the full Item-Struct
GetItem( &tv_item );
// Set the wanted style
nStyle = ILD_TRANSPARENT( tv_item.state & TVIS_OVERLAYMASK );
}
// Draw Image to the compatible DC
if( FALSE == pImageList->Draw( &memDC, iImageNumber, point, nStyle ) )
{
// Drawing of the Image failed
return NULL;
}
// Create logical palette if device support a palette
if( dc.GetDeviceCaps( RASTERCAPS ) & RC_PALETTE )
{
UINT nSize = sizeof(LOGPALETTE) + ( sizeof(PALETTEENTRY) * 256 );
LOGPALETTE* pLP = (LOGPALETTE*)new BYTE[nSize];
pLP->palVersion = 0x300;
pLP->palNumEntries = (unsigned short)GetSystemPaletteEntries( dc, 0, 255,
pLP->palPalEntry );
// Create the palette
pal.CreatePalette( pLP );
// Free memory
delete[] pLP;
}
memDC.SelectObject( pOldBitmap );
// Convert the bitmap to a DIB
return DDBToDIB( bitmap, BI_RGB, &pal );
}
Tags:
作者:佚名评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论