• ### Popular Now

• 13
• 15
• 27
• 9
• 9

#### Archived

This topic is now archived and is closed to further replies.

# A problem with GDI

This topic is 5103 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
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:

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