A problem with GDI
I am trying to load a PNG file with GDI. The PNG loads just fine. I checked the values of the pixels and they seem just fine. I am just having a problem setting it to a GDI bitmap.
This is a line from my code:
hbmp=CreateDIBitmap(bhdc,pg,CBM_INIT,fiximage,(BITMAPINFO*) pg, DIB_RGB_COLORS);
bhdc is an HDC created with "CreateCompatibleDC(0)"
pg is a pointer to data with a BITMAPINFOHEADER, followed by the bits of the image.
fiximage is the pointer to the bits of the image.
The problem is when I BitBlt "hbmp" onto the screen, the image is black with a few white dots. The dimensions of the image are okay. It just shows nothing but a monochrome image. What am I doing wrong? Thank you.
gdi programming was something i did a long long time ago.. but if i remember correctly, CreateCompatibleDC(0) will just create a 0x0 or 1x1 monochrome image. You want to do something like this:
note: hbm is the bitmap handle.
-j
HDC hdestdc=GetDC(hwnd); //get dc that you want to be compatible withhdc=CreateCompatibleDC(hdestdc); //create a new dc that is compatible with the dc associated with hwndReleaseDC(hwnd,hdestdc); //don''t need hdestdc anymoreSelectObject(hdc,hbm); //bust the bmp into the new dc
note: hbm is the bitmap handle.
-j
Is that regular GDI or GDI+ ? I didn''t know you could load a PNG using plain GDI. I have some great code for setting up the BITMAP but it''s for GDI (not GDI+) and only works when you already loaded the bitmap bits (I used the IJG JPEG Library for it).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement