|
|
这是我自己写的一个dib类的绘图函数
只要构造好头部就可以了
稳中的乱麻是中文的注释 复制到这里就有问题了
不知道怎么回事哈
现在忙没有时间该过来
以后发贴补这样了
BOOL CDIB::PaintDIBOnDC(HDC hDC , RECT destRect)
{
LPSTR lpbiHdr ;//λͼµÄÍ·ÐÅÏ¢
LPSTR lpBits ;//λͼµÄÊý¾ÝÐÅÏ¢
BOOL bSuccess = FALSE ;//³É¹¦Óë·ñµÄ±ê¼Ç
HPALETTE hPalette = NULL ;//µ÷É«°å
HPALETTE hOldPalette = NULL ;//µ÷É«°å
if(!this->m_hDIB)
{
//ûÓйØÁªÎ»Í¼
MessageBox(NULL,"ûÓйØÁªÎ»Í¼","»æÍ¼´íÎó",MB_OK);
return FALSE ;
}
//λͼͷÐÅÏ¢
lpbiHdr = (LPSTR)::GlobalLock(this->m_hDIB) ;
//λͼÊý¾ÝÐÅÏ¢
lpBits =lpbiHdr + sizeof(BITMAPINFOHEADER) + GetColorNum() * sizeof(RGBQUAD) ;
//´´½¨dibµÄµ÷É«°å
hPalette = CreatePalettle() ;
//ʵÏÖµ÷É«°å
if(hPalette)
{
hOldPalette = SelectPalette(hDC,hPalette,TRUE) ;
RealizePalette(hDC) ;
}
//ÉèÖÃÏÔʾģʽ
::SetStretchBltMode(hDC, COLORONCOLOR);
//»æÍ¼
/*
bSuccess = ::StretchDIBits( hDC ,
destRect.left ,
destRect.top ,
destRect.right-destRect.left ,
destRect.bottom-destRect.top,
0 ,
0 ,
GetWidth() ,
GetHeight(),
lpBits ,
(LPBITMAPINFO)lpbiHdr ,
DIB_RGB_COLORS ,
SRCCOPY
);
*/
///*
// ÏÔʾÔÚÔ¤¶¨ÇøÓòµÄÖмä
int destX = destRect.left + (destRect.right - destRect.left - GetWidth()) / 2 ;
int destY = destRect.top + (destRect.bottom - destRect.top - GetHeight()) / 2 ;
bSuccess = ::SetDIBitsToDevice( hDC , \
destX , \
destY, \
GetWidth() , \
GetHeight(), \
0 , \
0 , \
0, \
GetHeight(), \
lpBits , \
(LPBITMAPINFO)lpbiHdr , \
DIB_RGB_COLORS \
);
//*/
//»Ö¸´µ÷É«°å
if(hOldPalette)
{
SelectPalette(hDC,hOldPalette,FALSE) ;
}
//½âËø
::GlobalUnlock(this->m_hDIB);
return bSuccess;
}
yangwen 于 2004-07-30 01:24:30.0 编辑
[回复该贴]
|