Provides a powerful set of graphics features by creating a Microsoft Windows device context, using the specified bitmap as the display surface.


#include "l_bitmap.h"

L_LTKRN_API L_HDC L_CreateLeadDC(pBitmap)



Pointer to the LEAD bitmap handle referencing the image data.


Value Meaning
>0 Function was successful. The return value is the HDC.
NULL An error occurred.


It is recommended to use L_CreateLeadDC2 instead of this function, because L_CreateLeadDC2 returns an error indicating the reason for failure.

This function allows you to create an infinite number of drawing capabilities such as paint, erase, color erase and brush, pen, spray gun, flood fill, color tube, text overlay, curve, line, rectangle, polygon, ellipse, freehand shapes, cut and paste, and more.

All Windows GDI functions can be used to draw to the bitmap using the returned HDC. The HDC must be freed with the L_DeleteLeadDC function.

Note: For WIN32 applications, this function ensures that the bitmap's view perspective is BOTTOM_LEFT, flipping the bitmap if necessary. This can affect functions that use bitmap coordinates. For more information, refer to Accounting for View Perspective.

If a region is defined for the bitmap, GDI functions act only on the region, not on the entire bitmap.

The DIB driver supports only 1, 4, 8, 16, 24 and 32 bit images. If you are using an image that has some other number of bits per pixel, you must use L_ColorResBitmap to change the image to a bits per pixel value supported by the DIB driver.

Required DLLs and Libraries


Win32, x64.

See Also




For complete sample code, refer to the DRAW example.
This example uses GDI functions to draw an ellipse on the bitmap.

L_INT CreateLeadDCExample(L_VOID) 
   L_INT nRet; 
   BITMAPHANDLE LeadBitmap;   /* Bitmap handle for the image */ 
   HDC          LeadDC; /* Device context for the LEAD bitmap */ 
   L_INT        StartGDIX, StartGDIY, EndGDIX, EndGDIY; /* Drawing coordinates */ 
   /* Load a bitmap at its own bits per pixel */ 
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("ImageProcessingDemo\\Image3.cmp")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if(nRet != SUCCESS) 
      return nRet; 
   /* Create the device context */ 
   LeadDC = L_CreateLeadDC(&LeadBitmap); 
   /* Set the drawing coordinates in the top left quadrant of the bitmap */ 
   StartGDIX = BITMAPWIDTH(&LeadBitmap) / 8; 
   EndGDIX = BITMAPWIDTH(&LeadBitmap) / 2; 
   StartGDIY = BITMAPHEIGHT(&LeadBitmap) / 8; 
   EndGDIY = BITMAPHEIGHT(&LeadBitmap) / 2; 
   /* Convert the coordinates if necessary */ 
   if (LeadBitmap.ViewPerspective != TOP_LEFT) 
      L_PointToBitmap ( &LeadBitmap, TOP_LEFT, & StartGDIX, & StartGDIY ); 
      L_PointToBitmap ( &LeadBitmap, TOP_LEFT, & EndGDIX, & EndGDIY ); 
   /* Draw the ellipse */ 
   SelectObject(LeadDC, GetStockObject(WHITE_PEN)); 
   SelectObject(LeadDC, GetStockObject(NULL_BRUSH)); 
   SetROP2(LeadDC, R2_NOT); 
   Ellipse(LeadDC, StartGDIX, StartGDIY, EndGDIX, EndGDIY); 
   /* Delete the device context */ 
   return SUCCESS;  

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

LEADTOOLS Raster Imaging C API Help

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.