![]() |
| Home | Introduction | Table of Contents | Updates | New Stuff | Links | About the Authors | Ordering | ||
| |
||
| Sample Project: Printing a Bitmap | |
| Synopsis: This sample project demonstrates how to print a bitmap by using the StretchDIBits function. Abstract: As I mentioned in Chapter 6, a color device-dependent bitmap (DDB) is--as it's name suggests--a device dependent entity. Recall that the hdc parameter of the CreateCompatibleBitmap function is your way of telling the function with which device you want the DDB to be compatible; in turn, the CreateCompatibleBitmap function will instruct the corresponding device driver to create the DDB. Because a DDB that's been created by a specific device is stored in a format known only to that device, you can use blitting functions--such as BitBlt and StretchBlt--to render a DDB only to the device with which the DDB is compatible. For example, if you create a DDB that's compatible with the screen (say, by passing the CreateCompatibleBitmap function a handle to the screen's DC or by using the LoadImage function), you can't use BitBlt or StretchBlt to draw this bitmap to a printer's device context. This limitation is documented by Microsoft in the following Knowledge Base article: Q195830-INFO: Blitting Between DCs for Different Devices Is Unsupported. In contrast, and as mentioned in Chapter 7, the format of a device-independent bitmap (DIB) is not device specific. Remember, a DIB is nothing more than a block of memory that contains a header, a color table, and an array of pixels. This means that you can safely transfer a DIB (or a DIB section bitmap) to a printer's device context by using the StretchDIBits function. This sample project demonstrates: (1) how to convert a DDB to a DIB; (2) how to convert a DIB section bitmap to a DIB; and (3) how to use the StretchDIBits function to send a DIB to the printer. This sample project also demonstrates how to work around the limitations of the StretchDIBits function on Windows 9x/Me-based systems by using a technique called banding. Keywords: Device-dependent bitmap, Device-independent bitmap, DIB section bitmap, DDB, DIB, StretchDIBits, GetDIBits. Download: |
|
|
||
|
Copyright
© 2001 Damon Chandler and Michael Fötsch
|
||
|
|