Microsoft KB Archive/201955

From BetaArchive Wiki

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

Q201955



The information in this article applies to:


  • Microsoft Win32 Application Programming Interface (API)





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:

Q139165 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:


Q66595 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:

Q186221 SAMPLE: DibSectn.exe Uses DIBSections in Win32

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


http://msdn.microsoft.com/library/techart/msdn_dibs2.htm



STATUS

This behavior is by design.



REFERENCES

CreateDIBSection in the Platform SDK Documentation:

http://msdn.microsoft.com/library/psdk/gdi/bitmaps_5d4g.htm

Additional query words:

Keywords : kbBitmap kbDevContext kbGDI kbDSupport kbgrpdsvc
Issue type : kbprb
Technology : kbAudDeveloper kbWin32sSearch kbWin32API


Last Reviewed: June 15, 2001
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.