CreateDIBitmap()如何得到本地bmp的HBITMAP?在线等......
已知本地bmp路径strFileName;如何用CreateDIBitmap()得到该bmp的HBITMAP?...
已知本地bmp路径 strFileName;
如何用CreateDIBitmap()得到该bmp的HBITMAP? 展开
如何用CreateDIBitmap()得到该bmp的HBITMAP? 展开
展开全部
CFile file;
if( !file.Open(strFileName, CFile::modeRead) )
return FALSE;
BITMAPFILEHEADER bmfHeader;
long nFileLen;
nFileLen = file.GetLength();
if (file.Read((LPSTR)&bmfHeader, sizeof(bmfHeader)) != sizeof(bmfHeader))
return FALSE;
if (bmfHeader.bfType != ((WORD)('M' <<8) | 'B'))
return FALSE;
HGLOBAL hDIB = ::GlobalAlloc(GMEM_FIXED, nFileLen);
if (hDIB == 0)
return FALSE;
if (file.ReadHuge((LPSTR)hDIB, nFileLen - sizeof(BITMAPFILEHEADER)) !=
nFileLen - sizeof(BITMAPFILEHEADER) )
{
::GlobalFree(hDIB);
return FALSE;
}
BITMAPINFO &bmInfo = *(LPBITMAPINFO) ::GlobalLock(hDIB) ;
BITMAPINFOHEADER *pInfoHead = (BITMAPINFOHEADER *)hDIB;
int nHeaderSize=sizeof(BITMAPINFOHEADER);
BYTE *pBmpPixelBuffer=(BYTE *)&bmInfo+bmfHeader.bfOffBits - sizeof(BITMAPFILEHEADER);
CDC dc;
dc.CreateDC("DISPLAY",NULL,NULL,NULL);
HBITMAP hBitmap;
hBitmap=CreateDIBitmap(dc.m_hDC,(BITMAPINFOHEADER *)&bmInfo,CBM_INIT,(VOID *)pBmpPixelBuffer,&bmInfo,DIB_RGB_COLORS);
//do you job
::GlobalUnlock (hDIB);
::GlobalFree(hDIB);
if( !file.Open(strFileName, CFile::modeRead) )
return FALSE;
BITMAPFILEHEADER bmfHeader;
long nFileLen;
nFileLen = file.GetLength();
if (file.Read((LPSTR)&bmfHeader, sizeof(bmfHeader)) != sizeof(bmfHeader))
return FALSE;
if (bmfHeader.bfType != ((WORD)('M' <<8) | 'B'))
return FALSE;
HGLOBAL hDIB = ::GlobalAlloc(GMEM_FIXED, nFileLen);
if (hDIB == 0)
return FALSE;
if (file.ReadHuge((LPSTR)hDIB, nFileLen - sizeof(BITMAPFILEHEADER)) !=
nFileLen - sizeof(BITMAPFILEHEADER) )
{
::GlobalFree(hDIB);
return FALSE;
}
BITMAPINFO &bmInfo = *(LPBITMAPINFO) ::GlobalLock(hDIB) ;
BITMAPINFOHEADER *pInfoHead = (BITMAPINFOHEADER *)hDIB;
int nHeaderSize=sizeof(BITMAPINFOHEADER);
BYTE *pBmpPixelBuffer=(BYTE *)&bmInfo+bmfHeader.bfOffBits - sizeof(BITMAPFILEHEADER);
CDC dc;
dc.CreateDC("DISPLAY",NULL,NULL,NULL);
HBITMAP hBitmap;
hBitmap=CreateDIBitmap(dc.m_hDC,(BITMAPINFOHEADER *)&bmInfo,CBM_INIT,(VOID *)pBmpPixelBuffer,&bmInfo,DIB_RGB_COLORS);
//do you job
::GlobalUnlock (hDIB);
::GlobalFree(hDIB);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询