Hi everyone, I am having a problem loading bitmap files. I have gone through various tutorials that I've found on the web, but with little success. I am using the win32 api, no MFC or SDL, just win32 api code.
I already know how to load the image using LoadImage, but this does not meet my requirements. I need to be able to load the bitmap into a memory DC, assign a HBITMAP handle to it so I can BitBlt it to my needs. Can anyone offer any suggestions as to what I am doing wrong...The images I am using are all 24bit, and from what I have read this means that I do not need to worry about palettes? When stepping through the code in debug, I can see that the FILEHEADER and INFOHEADER are read in correctly, and when I use GetObject on the HBITMAP returned from CreateDIBitmap, it gives me the right width and height, but I did notice that it shows 1 bits per pixel, should this not be 24 ?
HDC hdcmem = CreateCompatibleDC(hdc);
HBITMAP hbmMem, hbmFinal;
ifstream bmf("C:\\cpp\\bitmap\\example.bmp", ios_base::in | ios_base::binary);
bmf.read(reinterpret_cast<char *>(&bmfh), sizeof(BITMAPFILEHEADER));
if(bmfh.bfType != 19778)
long bmsize = bmfh.bfSize - bmfh.bfOffBits;
bmf.read(reinterpret_cast<char *>(&bmih), sizeof(BITMAPINFOHEADER));
int bmcolors = bmih.biClrUsed ? bmih.biClrUsed : 1 << bmih.biBitCount;
char *bmdata = new char[bmsize];
hbmfile = CreateDIBitmap(hdcMem, &bmih, CBM_INIT, bmdata, (BITMAPINFO *)&bmih, DIB_RGB_COLORS);
hbmFinal = (HBITMAP)SelectObject(hdcMem, hbmfile);
BitBlt(hdc, 0,0, bmMem.bmWidth, bmMem.bmHeight,hdcMem,0,0,SRCCOPY);