#include "ltwrappr.h"

virtual COLORREF LBitmapBase::GetPixelColor(nRow, nCol)

L_INT nRow;

row number of the pixel

L_INT nCol;

column number of the pixel

Returns the color of the specified pixel.




The row number of the pixel. This is a zero-based value.


The column number of the pixel. This is a zero-based value.


Returns the color of the specified pixel from the class object's bitmap.

This function returns a COLORREF value which may represent an index into a bitmap's palette, a grayscale value (Medical Imaging only), or red, green, and blue color values.

If an error occurs, this function returns 0x80000000.


The standard Windows values for COLORREF represent either red, green, and blue color values, or an index into the bitmap's palette. A COLORREF value with the format 0x00BBGGRR represents the blue, green, and red color values for the specified pixel, where 0xBB is the blue value, 0xGG is the green value and 0xRR is the red value. If 0x01000000 is set in the COLORREF value (0x010000ZZ), the lower 8 bits (0xZZ) represent an index into the bitmap's palette which holds the color value. These COLORREF values can be used with any Windows function and macro that takes a COLORREF parameter.

In the Document/Medical toolkits, the COLORREF value may represent a 16 bit grayscale value if pBitmap is a 12 or 16-bit grayscale bitmap. So that the value is not confused with an RGB value, the COLORREF_GRAY16 mask (0x04000000) is set. In this case (0x0400YYYY), the lower 16 bits (0xYYYY) of the COLORREF value represent the 16-bit grayscale value. This is not a standard Windows value. Therefore, LEADTOOLS functions will recognize a COLORREF having this format, but Windows functions will not. To use a COLORREF value of this type in a non-LEADTOOLS function, you must do the following:

COLORREF color; 
color = GetPixelColor(x, y); 
if(color & COLORREF_GRAY16) 
{ // nonstandard colorref value, convert it to a windows COLORREF 
   // get an 8 bit gray value corresponding to the 16 bit gray value 
   L_UCHAR gray = (color & 0xFFFF) >> 8; 
   // use the standard windows RGB macro to get a windows COLORREF 
   color = RGB(gray, gray, gray); 

Calling LBitmapBase::GetPixelColor on a 32-bit grayscale bitmap returns an error  0x80000000.
To get pixel data for a 32-bit grayscale bitmap, use LBitmapBase::GetPixelData, LBitmapBase::GetRow or LBitmapBase::GetRowCol.

You can use the LBitmapBase::PutPixelColor function to assign the returned value to another pixel.

This function always uses TOP_LEFT ViewPerspective coordinates to specify the pixel. Therefore, you do not have to account for the view perspective of the bitmap. For more information, refer to Accounting for View Perspective.

If you specify a pixel that is outside the bitmap or outside the region (if the bitmap has one), this function returns an error.

Required DLLs and Libraries


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


Win32, x64.

See Also


LBitmapBase::PutPixelColor, Class Members


Raster Image Functions: Getting and Setting Pixel Values


Using Color Values in LEADTOOLS


#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName 
L_INT LBitmapBase__GetPixelColorExample() 
   L_INT nRet; 
   LBitmapBase MyBitmap; 
   COLORREF Color; 
   nRet =MyBitmap.Load(MAKE_IMAGE_PATH(TEXT("image1.cmp")),24); 
   if(nRet !=SUCCESS) 
      return nRet; 
   nRet =MyBitmap.PutPixelColor(20,20,Color); 
   if(nRet !=SUCCESS) 
      return nRet; 
   return SUCCESS; 

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Raster Imaging C++ Class Library Help