L_PrintBitmap

#include "l_bitmap.h"

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

Prints a bitmap to a the specified device, using the LEADTOOLS built-in resizing and color resolution functions for preprocessing the image as necessary to match the output device and parameters.

Parameters

L_HDC hDC

Handle to the device context (DC) where the bitmap is to print. The mapping mode of the device context must be MM_TEXT. Pass NULL to let the function use the system's default printer.

pBITMAPHANDLE pBitmap

Pointer to the bitmap handle referencing the bitmap to print.

L_INT nX

X position to start the print. Pass a 0 to center the image horizontally on the page.

L_INT nY

Y position to start the print. Pass a 0 to center the image vertically on the page.

L_INT nWidth

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

Pass a 0 to let the function calculate the width. If you specify only the width or only the height, the function calculates the remaining dimension. If you pass zeros for both width and height, the function calculates the maximum dimensions that fit on the page while preserving the aspect ratio.

L_INT nHeight

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

Pass a 0 to let the function calculate the height. If you specify only the width or only the height, the function calculates the remaining dimension. If you pass zeros for both width and height, the function calculates the maximum dimensions that fit on the page while preserving the aspect ratio.

L_BOOL 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

Value Meaning
>0 Function was successful. If bEndDOC is FALSE, the return value is the printer HDC.
0 An error occurred.

Comments

You can specify the position and dimensions of the printed image, or let the function calculate values for you as follows:

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. If fEndDOC is FALSE, you can use the returned hDC to draw to the current printer page.

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

To update a status bar or detect a user interrupt during execution of this function, refer to L_SetStatusCallback.

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

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 PrintBitmapExample(L_VOID) 
{ 
   
   #ifndef _fmemset 
   #define _fmemset memset 
   #endif 
 
   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 */ 
   PRINTDLG       PrintOpts; /* Print dialog structure */ 
   DOCINFO        DocInfo; /* Document information structure */ 
 
   /* Load a bitmap at its own bits per pixel  */ 
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("ocr1.tif")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if(nRet != SUCCESS) 
      return nRet; 
   /* Get the printer DC */ 
   _fmemset( &PrintOpts, 0, sizeof(PrintOpts)); 
   PrintOpts.lStructSize = sizeof(PrintOpts); 
   PrintOpts.Flags = PD_RETURNDC; 
   if( !PrintDlg(&PrintOpts) ) 
        return CommDlgExtendedError(); 
   if( (PrinterDC = PrintOpts.hDC) == NULL ) 
   { 
     if( PrintOpts.hDevMode ) GlobalFree(PrintOpts.hDevMode); 
     if( PrintOpts.hDevNames) GlobalFree(PrintOpts.hDevNames); 
     return ERROR_NULL_PTR ; 
   } 
   /* Initialize the document to be printed */ 
   _fmemset( &DocInfo, 0, sizeof(DocInfo) ); 
   DocInfo.cbSize = sizeof(DocInfo); 
   DocInfo.lpszDocName = TEXT("L_PrintBitmap example"); 
   /* 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); 
   } 
   /* Start the print job */ 
   if( StartDoc(PrinterDC, &DocInfo) <= 0) 
   { 
     if( PrintOpts.hDevMode ) GlobalFree(PrintOpts.hDevMode); 
     if( PrintOpts.hDevNames) GlobalFree(PrintOpts.hDevNames); 
     DeleteDC(PrinterDC); 
     return GetLastError() ; 
   } 
   StartPage(PrinterDC); 
   /* Print the first image */ 
    L_PrintBitmap (PrinterDC, &LeadBitmap, 1, 1, PrintWidth, PrintHeight, FALSE); 
   /* Print the second image */ 
   L_PrintBitmap (PrinterDC, &LeadBitmap, 1, HeightAllowed * 6/5, PrintWidth, PrintHeight, FALSE); 
 
   /* Flush the page and finish the print job */ 
   EndPage( PrinterDC ); 
   EndDoc( PrinterDC ); 
   if( PrintOpts.hDevMode ) GlobalFree(PrintOpts.hDevMode); 
   if( PrintOpts.hDevNames) GlobalFree(PrintOpts.hDevNames); 
   DeleteDC(PrinterDC); 
 
   if(LeadBitmap.Flags.Allocated) 
      L_FreeBitmap(&LeadBitmap); 
 
   return SUCCESS; 
} 

Help Version 20.0.2020.4.3
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help