VC加载显示bmp图片的函数

时间:2023-03-08 17:54:48
VC加载显示bmp图片的函数
void ShowBitmap(HDC hdc,const char *srcpath)
{
HBITMAP hBitmap = (HBITMAP)::LoadImage(0, srcpath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
BITMAP Bitmap ;
GetObject (hBitmap, sizeof (BITMAP), &Bitmap) ;
int nWidth = Bitmap.bmWidth;
int nHeight = Bitmap.bmHeight;
HDC hMemDc = CreateCompatibleDC(hdc);
HGDIOBJ hOB = SelectObject(hMemDc, hBitmap);
BitBlt(hdc,0,0,nWidth,nHeight,hMemDc,0,0,SRCCOPY);
SelectObject(hMemDc, hOB);
DeleteObject(hBitmap);
DeleteDC(hMemDc);
}