0

I couldn't find any documentation for CreateCompatibleBitmap() or CreateDIBSection() that indicates if the bitmap is initialized or not and if so, what it is initialized to? I would presume it does and it's black? Are my presumptions correct? Is it documented?

TIA!!

user3161924
  • 1,849
  • 18
  • 33
  • I would assume the same but I don't have any documentation on this nor have I explicitly tested it. For safety just do a BitBlt(.., BLACKNESS) to be sure its black (or WHITENESS for white). – Lukas Thomsen Aug 08 '20 at 06:10
  • I think it depends how GDI obtained memory. If it needs to get it from system, it would be cleared so there is no leak of information from one process to another. If request can be satisfied from current process memory it could get random contents. – Daniel Sęk Aug 08 '20 at 07:46
  • @dan That doesn't make sense. The GDI was invented at a time, when processes shared a single address space. And in Windows NT, the system doesn't keep track whether any given page of RAM was previously used by a different or the same process. – IInspectable Aug 08 '20 at 09:38

1 Answers1

0

According to the CreateCompatibleBitmap:

Remarks

The color format of the bitmap created by the CreateCompatibleBitmap function matches the color format of the device identified by the hdc parameter. This bitmap can be selected into any memory device context that is compatible with the original device.

Because memory device contexts allow both color and monochrome bitmaps, the format of the bitmap returned by the CreateCompatibleBitmap function differs when the specified device context is a memory device context. However, a compatible bitmap that was created for a nonmemory device context always possesses the same color format and uses the same color palette as the specified device context.

Note: When a memory device context is created, it initially has a 1-by-1 monochrome bitmap selected into it. If this memory device context is used in CreateCompatibleBitmap, the bitmap that is created is a monochrome bitmap. To create a color bitmap, use the HDC that was used to create the memory device context,

So if you use the memory device, the bitmap that is created is a monochrome bitmap(black and white).

More references:Memory Device Contexts and The result of CreateCompatibleDC only has two colors

So you can set a bitmap compatible with that DC so that you will get a larger monochrome bitmap.

Zeus
  • 3,703
  • 3
  • 7
  • 20
  • Hi,if this answer did help to you, please feel free to mark it to help people with the same issue, and let me know if you have any problem.Thanks. – Zeus Sep 04 '20 at 06:36