Loading a Data Set (C#)
Take the following steps to start a project and to add some code that loads a DICOM Data Set and prints information about the data set:
1. |
Start Visual Studio .NET. |
|
2. |
Create new Windows Application C# project. |
|
3. |
Add the LEAD COM Objects to your project. |
|
|
On the Tools pull-down menu, use the Add/Remove Toolbox Items... option, select the COM Components Tab, then select the LEAD Raster View Control (14.5). |
|
|
On the Project
pull-down menu, use the Add Reference...
option, select the COM Tab, then select the following: |
|
4. |
Select the LEAD Raster View Control, then add the control to your main form. |
|
5. |
Add a button to your form and name it as follows: |
|
|
Name |
Text |
|
LoadImage |
Load Image |
6. |
Add the following initialization code to the main form's Load event handler. In online help, you can use the Edit pull-down menu to copy the block of code. |
//class data-members
private LTDICLib.LEADDicomDS LEADDICOM1 = new LTDICLib.LEADDicomDSClass();
private void Form1_Load(object sender, System.EventArgs e)
{
//Unlock DICOM support.
//Note that this is a sample key, which will not work in your toolkit.
LTDicomKernelLib.LEADDicomFactory Factory = new LTDicomKernelLib.LEADDicomFactory();
LTDicomKernelLib.LEADDicomKernel DicomKernel = null;
string szLic = null;
szLic = "LEADTOOLS OCX Copyright (c) 1991-2005 LEAD
Technologies, Inc.";
DicomKernel = (LTDicomKernelLib.LEADDicomKernel)Factory.CreateObject("LEADDicomKernel.LEADDicomKernel",
szLic); LEADDICOM1 = (LTDICLib.LEADDicomDS) Factory.CreateObject("LEADDicomDS.LEADDicomDS",
szLic);
DicomKernel.UnlockSupport((short)LTDicomKernelLib.DicomSupportLockConstants.L_SUPPORT_MEDICAL,
"TestKey");
}
7. |
Code the LoadImage button's click procedure as follows: |
private void LoadImage_Click(object eventSender, System.EventArgs
eventArgs)
{
short nRet = 0;
short lCount = 0;
bool result = false;
LEADDICOM1.EnableMethodErrors = false;
nRet = LEADDICOM1.LoadDS("D:\\lead14\\dist\\images\\dicom\\image1.dic",
0);
if (nRet != (short)LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS)
MessageBox.Show("Error "
+ System.Convert.ToString(nRet) + " loading file!");
lCount = (short)LEADDICOM1.GetModuleCount(); LEADDICOM1.FindIndexModule(0);
result = LEADDICOM1.SetCurrentElement(LEADDICOM1.get_CurrentModule().get_Element(0).hElement);
if (result == true)
MessageBox.Show("There are "
+ System.Convert.ToString(lCount) + " modules in this data set."
+ ('\r') + "The first module has " + System.Convert.ToString(LEADDICOM1.get_CurrentModule().ElementCount)
+ " elements." + ('\r') + "The first element has: "
+ ('\r') + "Tag number:" + System.Convert.ToString(LEADDICOM1.get_CurrentElement().Tag,
16).ToUpper() + ('\r') + "VR: " + System.Convert.ToString(LEADDICOM1.get_CurrentElement().VR,
16).ToUpper());
LEADDICOM1.EnableMethodErrors = true;
}
8. |
Run your program to test it. |
9. |
Save the project to use as a starting point for other tasks in this tutorial. |