Using Color Values in LEADTOOLS

The standard Windows values for COLORREF represent either red, green, and blue color values, or an index into the image 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 image palette which holds the color value. These COLORREF values can be used with any Windows function and macro that takes a COLORREF parameter. Please note that just because an image has a palette, that does not mean the returned COLORREF value is automatically an index.

LEADTOOLS for .NET uses a Leadtools.RasterColor structure to specify a color. These structures can be converted to Windows COLORREF values with the RasterColor.ToArgb method. You can also create a Leadtools.RasterColor object from a COLORREF by using the RasterColor.FromArgb method.

In the Document/Medical Imaging editions, the COLORREF value may represent a 16 bit grayscale value if the Leadtools.RasterImage is a 12 or 16-bit grayscale image. So that the value is not confused with an RGB value, the 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 methods 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:

C#
int GetColorRef(RasterImage image, int x, int y) 
{ 
   RasterColor color = image.GetPixelColor(x, y); 
   // convert to Windows COLORREF 
   int clrref = color.ToArgb(); 
   const int COLORREF_GRAY16 = 0x04000000; 
   if((clrref & COLORREF_GRAY16) == COLORREF_GRAY16) 
   { 
      // nonstandard COLORREF value, convert it to a windows COLORREF 
      // get an 8 bit gray value corresponding to the 16 bit gray value 
      byte gray = (byte)((clrref & 0xFFFF) >> 8); 
      // use the equivalent of the standard Windows RGB macro to get a windows COLORREF 
      clrref = RGB(gray, gray, gray); 
   } 
   return clrref; 
} 
static int RGB(byte r, byte g, byte b) 
{ 
   return (r | (g << 8)) | (b << 16); 
} 

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

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