23.3.3 Modifying Bitmaps

DIBs offer many advantages over device-dependent bitmaps. Unlike device-dependent bitmaps, however, DIBs cannot be selected into a video device context. Before the DIB driver was available, this meant that applications could not take advantage of the extensive graphics device interface (GDI) functions to modify DIBs directly. To use GDI routines to draw in or otherwise modify a DIB, an application would follow a procedure such as this:

1.Create a memory device context.

2.Use the CreateDIBitmap function to convert the DIB to device-dependent format.

3.Select the device-dependent bitmap into the memory device context.

4.Call GDI routines to modify the device-dependent bitmap.

5.Use the GetDIBits function to convert the device-dependent bitmap to DIB format.

This method works well if you only use GDI routines to modify the bitmap. If you want to speed up certain operations by writing replacement functions that directly modify the DIB bits, however, the procedure can become complicated. The direct-manipulation routines work on the DIB, but the GDI routines work on the device-dependent bitmap.

Direct manipulation can be considerably faster than using equivalent GDI
routines; in one sample application, a direct-manipulation function (drawing a
triangle) ran eight times faster than the equivalent GDI operation. Also, direct-manipulation routines for other products may be reusable.

The DIB driver makes it possible for you to mix GDI calls with direct-manipulation routines, so you can combine the advantages of both methods.