L_INT LBitmapBase::ConvertToGrayScale(pBitmapSrc, uBitsPerPixel)
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.
The source bitmap object.
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.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
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.
Win32, x64.
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 Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document