Getting and setting window center and width Example for Visual Basic
' This example will add a new "Window Width" and
' "Window Center" to the dataset , or replace
' the existing one(s)
Dim bAddWindow
Dim WindowAttributes As LWindowAttributes
Dim iRet As Integer
Dim lWindowCount As Integer
Dim lWindowIndex As Integer
Dim iBitsStored As Integer
lWindowCount = 0
lWindowIndex = 0
bAddWindow = True
iBitsStored = 12
lWindowCount = LEADDICOM1.WindowCount
If (lWindowCount > 0) Then
iRet = LEADDICOM1.GetWindowAttributes(0, 0)
If (iRet <> 0) Then
MsgBox ("error")
Exit Sub
End If
Set WindowAttributes = LEADDICOM1.WindowAttributes
' Half the width for the first window
WindowAttributes.WindowWidth = WindowAttributes.WindowWidth / 2
WindowAttributes.WindowCenter = WindowAttributes.WindowCenter / 2
Else
' 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.
Set WindowAttributes = LEADDICOM1.WindowAttributes
WindowAttributes.WindowWidth = 2 ^ iBitsStored
WindowAttributes.WindowCenter = 2 ^ (iBitsStored - 1)
WindowAttributes.WindowCWExplanation = ""
End If
lWindowIndex = lWindowCount
If (bAddWindow = False) Then
' Delete the existing window(s)
iRet = LEADDICOM1.DeleteWindow (0)
If (iRet <> 0) Then
MsgBox ("error")
Exit Sub
End If
lWindowIndex = 0
End If
' Add the new window
iRet = LEADDICOM1.SetWindowAttributes (lWindowIndex, 0)
If (iRet <> 0) Then
MsgBox ("error")
Exit Sub
End If