WindowLevel example for C++ Builder
These 3 examples convert a bitmap to 12-bit grayscale and then perform window leveling on the four most significant bits of the image.
Ex1.
LEADRasterProcess* pRasterProc= NULL;
CoCreateInstance(CLSID_LEADRasterProcess, NULL, CLSCTX_ALL, IID_ILEADRasterProcess, (void**)&pRasterProc);
//WindowLevel for Display
pRasterProc->Grayscale (LEADRasterView1->Raster, 12); //Grayscale image to 12-bit
pRasterProc-> Release( );
LEADRasterView1->Raster->LevelLowBit = 8 ;//use 4 most significant bits
LEADRasterView1->Raster->LevelHighBit = 11;
LEADRasterView1->WindowLevel ();
Ex2.
LEADRasterProcess* pRasterProc= NULL;
CoCreateInstance(CLSID_LEADRasterProcess, NULL, CLSCTX_ALL, IID_ILEADRasterProcess, (void**)&pRasterProc);
//WindowLevel image processing
pRasterProc->Grayscale ( LEADRasterView1->Raster, 12 ); //Grayscale image to 12-bit
LEADRasterView1->Raster->LevelLowBit= 8 ;// use 4 most significant bits
LEADRasterView1->Raster->LevelHighBit= 11 ;
pRasterProc->WindowLevel ( LEADRasterView1->Raster ) ;
pRasterProc-> Release( );
Ex3.
//This example loads a 16-bit grayscale, fills the window level lookup table,
// and window levels the bitmap for display only
int i;
LEADRasterIO* pRasterIO= NULL;
LEADRasterProcess* pRasterProc= NULL;
CoCreateInstance(CLSID_LEADRasterIO, NULL, CLSCTX_ALL, IID_ILEADRasterIO, (void**)&pRasterIO);
CoCreateInstance(CLSID_LEADRasterProcess, NULL, CLSCTX_ALL, IID_ILEADRasterProcess, (void**)&pRasterProc);
//Load a 16-bit grayscale image
pRasterIO->Load (LEADRasterView1->Raster, AnsiToOLESTR("v:\\images\\image5.dic"), 0, 0, 1);
LEADRasterView1->AutoRepaint = False;
//Use all bits
LEADRasterView1->Raster->LevelLowBit = 0;
LEADRasterView1->Raster->LevelHighBit =(short)(LEADRasterView1->Raster->BitmapBits - 1);
LEADRasterView1->Raster->GetMinMaxBits ( ) ;
LEADRasterView1->Raster->GetMinMaxVal ( ) ;
//Set LUT so the range is from pure blue to pure red
for (i = LEADRasterView1->Raster->MinVal; i <= LEADRasterView1->Raster->MaxVal; i ++)
LEADRasterView1->Raster->set_LevelLUT (i, RGB((i % 256), 0, 256 - (i % 256)));
//Window level for display only--leave the bitmap data unchanged
LEADRasterView1->WindowLevel ();
LEADRasterView1->ForceRepaint ();
pRasterProc-> Release( );
pRasterIO-> Release( );