LBitmapBase::ConvertToGrayScale

Summary

Converts the class object's bitmap to an 8-, 12-, or 16-bit grayscale bitmap from a 1-, 4-, 8-, 16-, 24-, or 32-bit source LBitmapBase class object.

Syntax

#include "ltwrappr.h"

L_INT LBitmapBase::ConvertToGrayScale(pBitmapSrc, uBitsPerPixel)

Parameters

LBitmapBase * pBitmapSrc

The source bitmap object.

L_INT uBitsPerPixel

Value that indicates the bits per pixel to be used in the conversion of class object's bitmap. Possible values are 8, 12, or 16.

Returns

Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

Once the function is complete, the Order member of the class object's bitmap handle is set to ORDER_GRAY.

When converting to 12-bit or 16-bit grayscale, a Lookup table is not used. When converting to 8-bit grayscale, a Lookup table is used to get the RGB for each input pixel. The grayscale value corresponding to that RGB triple is used in the converted class object's bitmap.

When converting to 12-bit or 16-bit grayscale, the function uses the LowBit and HighBit data stored in the class object's bitmap. So the appropriate values for LowBit and HighBit in the converted class object's bitmap should be set before calling this function, otherwise the function will return an error code.

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

Support for 12 and 16-bit grayscale images is available only in the Document/Medical Imaging editions.

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

Example

This example loads a bitmap and changes it to 16-bit grayscale.

L_INT LBitmapBase__ConvertToGrayScaleExample() 
{ 
   L_INT nRet; 
   LBitmapBase LeadBitmap;   /* Bitmap handle to hold the loaded image. */ 
   LBitmapBase DstBitmap;   /* Bitmap handle to hold the result image. */ 
 
   /* Load the bitmap, keeping the bits per pixel of the file */ 
   nRet = LeadBitmap.Load(MAKE_IMAGE_PATH(TEXT("IMAGE1.CMP"))); 
   if(nRet != SUCCESS) 
      return nRet; 
 
   /* Change the bitmap to grayscale */ 
   DstBitmap.GetHandle()->LowBit = 0; 
   DstBitmap.GetHandle()->HighBit = 15; 
   nRet = DstBitmap.ConvertToGrayScale(&LeadBitmap, 16); 
   if(nRet != SUCCESS) 
      return nRet; 
 
   nRet = DstBitmap.Save(MAKE_IMAGE_PATH(TEXT("Result.BMP")), FILE_BMP, 24, 0, 0); 
   if(nRet != SUCCESS) 
      return nRet; 
 
   return SUCCESS; 
} 

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

LEADTOOLS Raster Imaging C++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.