L_PrintBitmapFast

#include "l_bitmap.h"

L_LTDIS_API L_HDC L_PrintBitmapFast (hDC, pBitmap, nX, nY, nWidth, nHeight, fEndDoc)

L_HDC hDC;

/* handle to the target device context (DC) */

pBITMAPHANDLE pBitmap;

/* pointer to the bitmap handle */

L_INT nX;

/* x position to start the print */

L_INT nY;

/* y position to start the print */

L_INT nWidth;

/* printed width */

L_INT nHeight;

/* printed height */

L_BOOL fEndDoc;

/* end of document indicator */

Prints a bitmap to the specified device. (This is the same as the L_PrintBitmap function, except that it does no preprocessing of the image.)

Parameter

Description

hDC

Handle to the device context (DC) where the bitmap is to print. The mapping mode of the device context must be MM_TEXT.

pBitmap

Pointer to the bitmap handle referencing the bitmap to print.

nX

X position to start the print.

nY

Y position to start the print.

nWidth

The printed width. The value is in dots, and the actual width depends on the dots per inch (DPI) of the printer.

nHeight

The printed width. The value is in dots, and the actual width depends on the dots per inch (DPI) of the printer.

fEndDoc

This is used to let LEADTOOLS know whether you plan to print another image on the same page or not.

 

Value

Meaning

 

TRUE

LEADTOOLS will free the hDC and send a paper eject.

 

FALSE

LEADTOOLS will assume that you plan to print another bitmap.

Returns

>0

Function was successful. If bEndDOC is FALSE, the return value is the printer HDC.

0

An error occurred.

Comments

The function is designed to let you print multiple bitmaps on the same page. To do so, call the function with the fEndDoc argument set to FALSE for each image except the last one on the page. Then call the function with the fEndDoc argument set to TRUE. If you do not set the fEndDoc argument to TRUE on the last call, the hDC will not be freed, and the page will not flush.

If pBitmap is NULL, the nX, nY, nWidth, and nHeight arguments are ignored and the returned DC is to the default printer, with the Windows C DLL functions StartDoc and StartPage already called. If fEndDoc is FALSE, you can use the returned hDC to draw to the current printer page. If youre printing more than one page and you passed FALSE for fEndDoc, be sure to call EndPage then StartPage between each call to L_PrintBitmapFast.

An alternative for greater flexibility is the L_PaintDC function, which you can use by specifying the printer as the display surface.

Required DLLs and Libraries

LTDIS

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Windows 2000 / XP/Vista.

See Also

Functions:

L_PrintBitmap, L_PrintBitmapGDIPlus

Topics:

Printing an Image

 

Printing a Single-Page Image with LEADTOOLS

 

Raster Image Functions: Printing Images

Example

For complete sample code, refer to the CHILD.C module of the DEMO example. This example determines the output size to fit the image on half of a page, and prints the bitmap twice on the same page.

 L_INT PrintBitmapFastExample(L_VOID)
{
   L_INT nRet;
   BITMAPHANDLE   LeadBitmap;    /* Bitmap handle for the image */
   HDC            PrinterDC;     /* DC for the printer */
   L_INT          WidthAllowed, HeightAllowed, WidthFactor, HeightFactor; /* For size calculations */
   L_INT          PrintWidth, PrintHeight; /* Width and height of the printed image */

   /* Load a bitmap at its own bits per pixel  */
   nRet = L_LoadBitmap (TEXT("%UserProfile%\\My Documents\\LEADTOOLS Images\\ocr1.tif"), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL);
   if(nRet != SUCCESS)
      return nRet;
   /* Get the printer DC */
   PrinterDC = L_PrintBitmapFast(NULL, NULL, 0, 0, 0, 0, FALSE);

   /* Initialize variables for fitting the image on half a page */
   WidthAllowed = GetDeviceCaps(PrinterDC,HORZRES);
   HeightAllowed = GetDeviceCaps(PrinterDC,VERTRES) * 4/10;
   HeightFactor = BITMAPHEIGHT(&LeadBitmap);
   WidthFactor = BITMAPWIDTH(&LeadBitmap);

   /* See if using the maximum width will make the image too tall */
   if((L_INT) (((L_INT32) WidthAllowed * HeightFactor) / WidthFactor) < HeightAllowed)
   { /* Use the maximum width, and calculate the height value */
      PrintWidth = WidthAllowed;
      PrintHeight = (L_INT) (((L_INT32) PrintWidth * HeightFactor) / WidthFactor);
   }
   else
   { /* Use the maximum height, and calculate the width value */
      PrintHeight = HeightAllowed;
      PrintWidth = (L_INT) (((L_INT32) PrintHeight * WidthFactor) / HeightFactor);
   }
   /* Print the first image */
   L_PrintBitmapFast(PrinterDC, &LeadBitmap, 1, 1, PrintWidth, PrintHeight, FALSE);
   /* Print the second image */
  L_PrintBitmapFast(PrinterDC, &LeadBitmap, 1, HeightAllowed * 6/5, PrintWidth, PrintHeight, TRUE);
   if(LeadBitmap.Flags.Allocated)
      L_FreeBitmap(&LeadBitmap);
   return SUCCESS;
}