Getting and setting window center and width Example for Delphi
// This example will add a new 'Window Width' and
// 'Window Center' to the dataset , or replace
// the existing one(s)
var
bAddWindow: Boolean;
WindowAttributes: LWindowAttributes;
nRet: Integer;
nWindowCount: Integer;
nWindowIndex: Integer;
nBitsStored: Integer;
begin
bAddWindow:= True;
nBitsStored:= 12;
nWindowCount:= LEADDicomDS1.WindowCount;
if(nWindowCount > 0)then
begin
nRet:= LEADDicomDS1.GetWindowAttributes(0, 0);
if(nRet <> 0)then
begin
ShowMessage('error');
Exit;
end;
WindowAttributes:= LEADDicomDS1.WindowAttributes;
// Half the width for the first window
WindowAttributes.WindowWidth:= WindowAttributes.WindowWidth / 2;
WindowAttributes.WindowCenter:= WindowAttributes.WindowCenter / 2;
end
else
begin
// This represents an identity VOI LUT transformation in the case
// where no Modality LUT is specified and the stored pixel data are
// iBitsStored bit unsigned integers.
WindowAttributes:= LEADDicomDS1.WindowAttributes;
WindowAttributes.WindowWidth:= Power(2, nBitsStored);
WindowAttributes.WindowCenter:= Power(2, nBitsStored - 1);
WindowAttributes.WindowCWExplaination:= '';
end;
nWindowIndex:= nWindowCount;
if(bAddWindow = False)then
begin
// Delete the existing window(s)
nRet:= LEADDicomDS1.DeleteWindow (0);
if(nRet <> 0)then
begin
ShowMessage ('error');
Exit;
end;
nWindowIndex:= 0
end;
// Add the new window
nRet:= LEADDicomDS1.SetWindowAttributes (nWindowIndex, 0);
if(nRet <> 0)then
begin
ShowMessage('error');
Exit;
end;
end;