Archived

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

A problem with GDI

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 with
hdc=CreateCompatibleDC(hdestdc); //create a new dc that is compatible with the dc associated with hwnd
ReleaseDC(hwnd,hdestdc); //don''t need hdestdc anymore
SelectObject(hdc,hbm); //bust the bmp into the new dc


note: hbm is the bitmap handle.

-j

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites