PRB: Blt from a Memory Device Context Does Not Produce an Image (201955)



The information in this article applies to:

  • Microsoft Win32 Application Programming Interface (API)
  • Microsoft Windows XP Home Edition
  • Microsoft Windows XP Professional
  • the operating system: Microsoft Windows XP 64-Bit Edition

This article was previously published under Q201955

SYMPTOMS

Calling a bit block transfer (Blt) function with a memory device context (DC) as the source DC does not produce an image and does not return FALSE to indicate failure.

CAUSE

The memory device context was created properly but has not had a bitmap selected into it.

In Windows, all memory DCs are created with a default 1-pixel by 1-pixel monochrome bitmap. If an application does not select an HBITMAP object into the memory DC, the only source or destination for the image bits is the single pixel in the default bitmap.

Note that the Blt function succeeded and an image was transferred to the destination DC. However, it is probably not noticeable because it has most likely created a single black pixel on the destination DC.

RESOLUTION

To create a memory DC that produces an image when it is used as a source DC in a bit block transfer function, create and select a bitmap into the memory DC that contains image pixels of some form.

For additional information on how to properly create a Memory Device Context, click the article number below to view the article in the Microsoft Knowledge Base:

139165 PRB: Memory DC Produces Monochrome Images

To initialize the image in the memory DC with an image stored as a device independent bitmap (DIB), see the following Knowledge Base article:

66595 INFO: Using SetDIBitsToDevice() with a Memory Device Context

Alternatively, an image in DIB format can be used with the CreateDIBSection function to create an HBITMAP for a memory DC that can be simultaneously initialized or changed through a pointer to the image bits and through a memory DC. For an example of how to use DIBs see the following Knowledge Base sample article:

186221 SAMPLE: DibSectn.exe Uses DIBSections in Win32

For more information on DIBs, see the article entitled "DIBs and Their Use" by Ron Gery:

STATUS

This behavior is by design.

REFERENCES

CreateDIBSection in the Platform SDK Documentation:

Modification Type:MinorLast Reviewed:4/4/2006
Keywords:kbDSWGDI2003Swept kbBitmap kbDevContext kbGDI kbprb KB201955