WINGDIAPI int WINAPI StretchDIBits( HDC hdc, int XDest, int YDest, int nDestWidth, int nDestHeight, int XSrc, int YSrc, int nSrcWidth, int nSrcHeight, CONST VOID *lpBits, CONST BITMAPINFO *lpBitsInfo, UINT iUsage, DWORD dwRop );
CBitmap::CreateBitmapIndirect BOOL CreateBitmapIndirect( LPBITMAP lpBitmap ); Return ValueNonzero if successful; otherwise 0.ParameterslpBitmapPoints to a BITMAP structure that contains information about the bitmap.将内存中位图信息填充到BITMAP结构中即可创建一个CBitmap对象。
HDC hdc,
int XDest,
int YDest,
int nDestWidth,
int nDestHeight,
int XSrc,
int YSrc,
int nSrcWidth,
int nSrcHeight,
CONST VOID *lpBits,
CONST BITMAPINFO *lpBitsInfo,
UINT iUsage,
DWORD dwRop
);
CDC MemDC;
MemDC.CreateCompatibleDC(pDC);
HDC phDC = pDC->GetSafeHdc();//获得pStaic的HDC
HANDLE hBitmap = ::LoadImage(NULL, strMapFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE |
LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
ASSERT(hBitmap);
HANDLE OldBitmap=(HBITMAP)MemDC.SelectObject(hBitmap);
pDC->BitBlt(0,0,1100,1100,&MemDC,0,0,SRCCOPY);
MemDC.SelectObject(OldBitmap);
BOOL CreateBitmapIndirect( LPBITMAP lpBitmap );
Return ValueNonzero if successful; otherwise 0.ParameterslpBitmapPoints to a BITMAP structure that contains information about the bitmap.将内存中位图信息填充到BITMAP结构中即可创建一个CBitmap对象。
最后bitblt().就可以了
这些函数的具体用法看msdn吧。很简单的
DisplayBitmap( const char * pBuffer, size_t szSize, CWnd * pWnd )
{
pBuffer所指向的内容就是一个完整的BMP文件的内容
我要把这个BMP显示在pWnd上.
我怎么样把pBuffer的数据传给CreateDIBSection?
}
{
if ( !pBuffer )
{
return;
}
ASSERT( pWnd );
if ( !::IsWindow(pWnd->m_hWnd) )
{
return;
} CDC * pDC = pWnd->GetDC();
ASSERT( pDC );
if ( !pDC )
{
return;
} CRect rect;
if ( !pRect )
{
pWnd->GetClientRect( &rect );
pRect = ▭
} //// 显示位图
LONG bmpWidth;
LONG bmpHeight;
DWORD bfOffBits;
WORD biBitCount;
void *pBmpInfo;
void *lpvBufBmp; bfOffBits = *( DWORD* )( pBuffer + 10 );
bmpWidth = *( LONG* )( pBuffer + 18 );
bmpHeight = *( LONG* )( pBuffer + 22 );
lpvBufBmp = pBuffer + bfOffBits;
pBmpInfo = pBuffer + 14;
biBitCount = *( WORD* )( pBuffer + 28 );
BITMAPINFO bmpInfo;
memcpy( &bmpInfo.bmiHeader, pBmpInfo, 40 );
bmpInfo.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );#if 1
::StretchDIBits( pDC->m_hDC,
pRect->left, pRect->top, pRect->Width(), pRect->Height(),
0, 0, bmpWidth, bmpHeight,
lpvBufBmp, &bmpInfo, DIB_RGB_COLORS, SRCCOPY );
#else BITMAP bitmap;
bitmap.bmType = 0;
bitmap.bmWidth = bmpInfo.bmiHeader.biWidth;
bitmap.bmHeight = bmpInfo.bmiHeader.biHeight;
bitmap.bmWidthBytes = bmpInfo.bmiHeader.biWidth * bmpInfo.bmiHeader.biBitCount / 8;
bitmap.bmPlanes = bmpInfo.bmiHeader.biPlanes;
bitmap.bmBitsPixel = bmpInfo.bmiHeader.biBitCount;
bitmap.bmBits = lpvBufBmp; //// HBITMAP hbitmap = ::CreateBitmapIndirect( &bitmap );
HBITMAP hbitmap = ::CreateBitmap( bmpWidth, bmpHeight, bitmap.bmPlanes, bitmap.bmBitsPixel, bitmap.bmBits );
DisplayBimap( hbitmap, pWnd, pRect );
DeleteObject( hbitmap );#endif
}这样写的函数显示出来的图片不正常
我应该怎么更正?