Available in LEADTOOLS Medical Imaging toolkits. |
WindowLevelBitmap example for C++ 4.0 and later
//This example loads a 16-bit grayscale, fills the window level lookup table,
//and window levels the bitmap for display only
void CMFC42samplesDlg::OnButtonWindowlevel()
{
long min;
long max;
long i;
//Load a 16-bit grayscale image
m_Lead1.Load("d:\\work\\images\\gray16.tif",0,0,1);
m_Lead1.SetAutoRepaint(FALSE);
//use all bits
m_Lead1.SetLevelLowBit(0);
m_Lead1.SetLevelHighBit(m_Lead1.GetBitmapBits() - 1);
m_Lead1.GetMinMaxBits();
m_Lead1.GetMinMaxVal();
max = m_Lead1.GetMaxVal();
min = m_Lead1.GetMinVal();
//set LUT so it ranges from pure blue to pure red
for (i=min; i<max; i++)
m_Lead1.SetLevelLUT(i, RGB(i % 256, 0, 256 - i % 256));
//Window level for display only--leave the bitmap data unchanged
m_Lead1.SetWindowLevelBitmap(TRUE);
m_Lead1.WindowLevel();
m_Lead1.ForceRepaint();
}