Using Banding to Print Images

Banding is a printing technique used to print full-page graphics on raster devices such as dot-matrix printers. In banding, an application prints an image by dividing the image into several bands (or slices) and sending each band to the printer separately. Banding lets you print complex graphics images without first creating the complete image in memory. This can reduce the memory requirements for printing and enhance system performance while printing operations are in effect. You can use banding with any printing device that has banding capability.

To use banding to print an image, follow these steps:

1.Use the CreateDC function to retrieve a device context for the printer.

2.Use the GetDeviceCaps function to make sure the printer is a banding device:

if (GetDeviceCaps(hPrinterDC, RASTERCAPS) & RC_BANDING)

3.Use the Escape function and the NEXTBAND escape to retrieve the coordinates of a band:

Escape(hPrinterDC, NEXTBAND, 0, (LPSTR) NULL, (LPRECT) &rcRect);

The function sets the rcRect structure to the coordinates of the current band. Coordinates are in device units, and all subsequent GDI calls are clipped to this rectangle.

4.Check the rcRect structure to see if it is an empty rectangle. The empty rectangle marks the end of the banding operation. If it is empty, terminate the banding operation.

5.Use the DPtoLP function to translate the rcRect points from device units to logical units.

DPtoLP(hPr, (LPRECT) &rcRect, 2);

6.Use GDI output and other functions to draw within the band. To save time, the application should carry out only those GDI calls that affect the current band. If an application does not need to save time, GDI will clip all output that does not appear in the band, so no special action is required.

7.Repeat steps 4 through 6.

Once the banding operation is complete, use the DeleteDC function to remove the printer device context.

The following example shows how to print using banding:

hPr = CreateDC(“EPSON”,

“EPSON FX-80”,

“LPT1:”,

(LPSTR) NULL);

if(hPr != NULL) {

if(GetDeviceCaps(hPr, RASTERCAPS) & RC_BANDING) {

Escape(hPr, STARTDOC, 4, (LPSTR) “Dog”, (LPSTR)NULL);

Escape(hPr, NEXTBAND, 0, (LPSTR)NULL, (LPRECT) &rcRect);

while(!IsRectEmpty(&rcRect)) {

DPtoLP(hPr, (LPRECT) &rcRect, 2);

/* Place your output function here.

* To save time, use rcRect to determine

* which functions need to be called for

* this band.

*/

Escape(hPr, NEXTBAND, 0, (LPSTR)NULL, (LPRECT) &rcRect);

}

Escape(hPr, NEWFRAME, 0, (LPSTR)NULL, (LPSTR)NULL);

Escape(hPr, ENDDOC, 0, (LPSTR)NULL, (LPSTR)NULL);

}

DeleteDC(hPr);

}