0

For someone who knows CreateDIBitmap troubleshootings

When I create it, passing all the parameters hopefully correct, I create it with passing data array (bits array). This array is taken from the same bitmap (idea is to create a new copy; for testing purpose). But after creation (it returns correct handle), the bitmap is correct, but palette is B&W. No colors. Why? Who knows?

skaffman
  • 398,947
  • 96
  • 818
  • 769
  • 1
    That will be difficult to answer without seeing your code. Can you post at least your call to `CreateDIBitmap()`? – Frédéric Hamidi Jul 12 '11 at 21:29
  • Show us the code, we can't see it from here. – David Heffernan Jul 12 '11 at 22:24
  • Hi Frederic, I found the cause: I don't know why, but when used compatibleDC (CreateCompatibleDC from screen DC), then it B&W. When hdcScreen then Colored. Somehow, I don't know why, but compatible is B&W always. { IntPtr hdcScreen = GetDC(GetDesktopWindow()); compatibleDC = CreateCompatibleDC(hdcScreen); m_hBkgFrame = CreateDIBitmap(hdcScreen, ref DIBHeader, CBM_INIT, buffer, ref DIBInf, DIB_RGB_COLORS); ReleaseDC(GetDesktopWindow(), hdcScreen); } –  Jul 12 '11 at 22:25
  • Pass NULL to `CreateCompatibleDC`, just like it says in the docs. Not that you appear to use it (and it seems this may be the issue). And please add your code by editing the question. Putting it in a comment does not work as you can see. – David Heffernan Jul 12 '11 at 22:37

1 Answers1

4

Your first comment is the key to the issue. You're using a memory device context, obtained through CreateCompatibleDC(), and the default bitmap selected in memory DCs is monochrome (1 bit per pixel).

CreateDIBitmap() uses that device context to determine the bit depth of the DIB it creates, so you end up with a monochrome DIB.

You could use CreateDIBSection() to supply your own bit depth, but the simplest solution is probably to pass hdcScreen to CreateDIBitmap() instead of compatibleDC.

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • Well, I found out it already. But your statement is right, thanks fro ya attention. Will set your statement as anser. ok –  Jul 12 '11 at 22:45