Imports Leadtools
Imports Leadtools.Dicom
Public Sub TestWCWW()
Dim dicomFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "IMAGE3.dcm")
'Make sure to initialize the DICOM engine, this needs to be done only once
'In the whole application
DicomEngine.Startup()
Dim ds As DicomDataSet = New DicomDataSet()
Using (ds)
'Load DICOM File
ds.Load(dicomFileName, DicomDataSetLoadFlags.None)
Dim bitsStored As Integer = 16
Dim add As Boolean = False 'Add a new window or replace the existing one(s)
Dim windowIndex As Integer = 0
Dim windowAttributes As DicomWindowAttributes = New DicomWindowAttributes()
If ds.GetWindowCount(0) > 0 Then
Dim attributes As DicomWindowAttributes = ds.GetWindow(0)
If Not attributes Is Nothing Then
windowAttributes.WindowCenter = attributes.WindowCenter / 2
windowAttributes.WindowWidth = attributes.WindowWidth / 2
End If
Else
windowAttributes.WindowCenter = 1 << (bitsStored - 1)
windowAttributes.WindowWidth = 1 << bitsStored
End If
windowIndex = ds.GetWindowCount(0)
If (Not add) Then
' Delete the existing window(s)
ds.DeleteWindow()
windowIndex = 0
End If
' Add the new window
ds.SetWindow(windowIndex, windowAttributes)
ds.Save(Path.Combine(LEAD_VARS.ImagesDir, "WCWW.dcm"), DicomDataSetSaveFlags.None)
End Using
DicomEngine.Shutdown()
End Sub
Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools;
using Leadtools.Dicom;
public void TestWCWW()
{
string dicomFileName = Path.Combine(LEAD_VARS.ImagesDir, "IMAGE3.dcm");
//Make sure to initialize the DICOM engine, this needs to be done only once
//In the whole application
DicomEngine.Startup();
using (DicomDataSet ds = new DicomDataSet())
{
//Load DICOM File
ds.Load(dicomFileName, DicomDataSetLoadFlags.None);
int bitsStored = 16;
bool add = false;//Add a new window or replace the existing one(s)
int windowIndex = 0;
DicomWindowAttributes windowAttributes = new DicomWindowAttributes();
if (ds.GetWindowCount(0) > 0)
{
DicomWindowAttributes attributes = ds.GetWindow(0);
if (attributes != null)
{
windowAttributes.WindowCenter = attributes.WindowCenter / 2;
windowAttributes.WindowWidth = attributes.WindowWidth / 2;
}
}
else
{
windowAttributes.WindowCenter = 1 << (bitsStored - 1);
windowAttributes.WindowWidth = 1 << bitsStored;
}
windowIndex = ds.GetWindowCount(0);
if (!add)
{
// Delete the existing window(s)
ds.DeleteWindow();
windowIndex = 0;
}
// Add the new window
ds.SetWindow(windowIndex, windowAttributes);
ds.Save(Path.Combine(LEAD_VARS.ImagesDir, "WCWW.dcm"), DicomDataSetSaveFlags.None);
}
DicomEngine.Shutdown();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
using Leadtools.Dicom.Constants;
using Leadtools;
using Leadtools.Dicom;
public async Task TestWCWW()
{
//Make sure to initialize the DICOM engine, this needs to be done only once
//In the whole application
DicomEngine.Startup();
using (DicomDataSet ds = new DicomDataSet())
{
//Load DICOM File
string filePath = @"Assets\IMAGE3.dcm";
StorageFile file = await Tools.AppInstallFolder.GetFileAsync(filePath);
ILeadStream stream = LeadStreamFactory.Create(file);
bool success = await ds.LoadAsync(stream, DicomDataSetLoadFlags.None);
Debug.Assert(success);
int bitsStored = 16;
bool add = false;//Add a new window or replace the existing one(s)
int windowIndex = 0;
DicomWindowAttributes windowAttributes = new DicomWindowAttributes();
if (ds.GetWindowCount(0) > 0)
{
DicomWindowAttributes attributes = ds.GetWindow(0);
if (attributes != null)
{
windowAttributes.WindowCenter = attributes.WindowCenter / 2;
windowAttributes.WindowWidth = attributes.WindowWidth / 2;
}
}
else
{
windowAttributes.WindowCenter = 1 << (bitsStored - 1);
windowAttributes.WindowWidth = 1 << bitsStored;
}
windowIndex = ds.GetWindowCount(0);
if (!add)
{
// Delete the existing window(s)
ds.DeleteWindow();
windowIndex = 0;
}
// Add the new window
ds.SetWindow(windowIndex, windowAttributes);
string dicomFileNameOutput = "WCWW.dcm";
StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(dicomFileNameOutput);
ILeadStream streamOutput = LeadStreamFactory.Create(saveFile);
using (IDisposable disposableOUT = streamOutput as IDisposable)
{
await ds.SaveAsync(streamOutput, DicomDataSetSaveFlags.None);
}
}
DicomEngine.Shutdown();
}
using Leadtools;
using Leadtools.Dicom;
using Leadtools.Examples;
public void TestWCWW(Stream dicomStream, Stream outputStream)
{
//Make sure to initialize the DICOM engine, this needs to be done only once
//In the whole application
DicomEngine.Startup();
using (DicomDataSet ds = new DicomDataSet())
{
//Load DICOM File
ds.Load(dicomStream, DicomDataSetLoadFlags.None);
int bitsStored = 16;
bool add = false;//Add a new window or replace the existing one(s)
int windowIndex = 0;
DicomWindowAttributes windowAttributes = new DicomWindowAttributes();
if (ds.GetWindowCount(0) > 0)
{
DicomWindowAttributes attributes = ds.GetWindow(0);
if (attributes != null)
{
windowAttributes.WindowCenter = attributes.WindowCenter / 2;
windowAttributes.WindowWidth = attributes.WindowWidth / 2;
}
}
else
{
windowAttributes.WindowCenter = 1 << (bitsStored - 1);
windowAttributes.WindowWidth = 1 << bitsStored;
}
windowIndex = ds.GetWindowCount(0);
if (!add)
{
// Delete the existing window(s)
ds.DeleteWindow();
windowIndex = 0;
}
// Add the new window
ds.SetWindow(windowIndex, windowAttributes);
ds.Save(outputStream, DicomDataSetSaveFlags.None);
}
DicomEngine.Shutdown();
}
Imports Leadtools
Imports Leadtools.Dicom
Public Sub TestWCWW(ByVal dicomStream As Stream, ByVal outputStream As Stream)
'Make sure to initialize the DICOM engine, this needs to be done only once
'In the whole application
DicomEngine.Startup()
Using ds As DicomDataSet = New DicomDataSet()
'Load DICOM File
ds.Load(dicomStream, DicomDataSetLoadFlags.None)
Dim bitsStored As Integer = 16
Dim add As Boolean = False 'Add a new window or replace the existing one(s)
Dim windowIndex As Integer = 0
Dim windowAttributes As DicomWindowAttributes = New DicomWindowAttributes()
If ds.GetWindowCount(0) > 0 Then
Dim attributes As DicomWindowAttributes = ds.GetWindow(0)
If Not attributes Is Nothing Then
windowAttributes.WindowCenter = attributes.WindowCenter / 2
windowAttributes.WindowWidth = attributes.WindowWidth / 2
End If
Else
windowAttributes.WindowCenter = 1 << (bitsStored - 1)
windowAttributes.WindowWidth = 1 << bitsStored
End If
windowIndex = ds.GetWindowCount(0)
If (Not add) Then
' Delete the existing window(s)
ds.DeleteWindow()
windowIndex = 0
End If
' Add the new window
ds.SetWindow(windowIndex, windowAttributes)
ds.Save(outputStream, DicomDataSetSaveFlags.None)
End Using
DicomEngine.Shutdown()
End Sub