LEADTOOLS Raster Imaging C++ Class Library Help > Classes and Member Functions > LBitmapBase > LBitmapBase Member Functions > LBitmapBase::ConvertToGrayScale |
#include "ltwrappr.h"
L_INT LBitmapBase::ConvertToGrayScale(pBitmapSrc, uBitsPerPixel)
LBitmapBase * pBitmapSrc; |
/* reference to the source LBitmapBase class */ |
L_INT uBitsPerPixel; |
/* number of bits */ |
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.
Parameter |
Description |
pBitmapSrc |
The source bitmap object. |
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
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
LTKRN 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
Functions: |
LBitmapBase::IsGrayScale, LBitmapBase::GrayScale, Class Members. |
Topics: |
|
|
Example
This example loads a bitmap and changes it to 16-bit grayscale.
#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName 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; }