Once the base of the tutorial application is completed, you can extend it with DICOM support using the following steps:
- First, you need to add a reference to the ImageGear for .NET DICOM Assembly.
- In the Solution Explorer, right-click on References, and choose Add Reference.
- Choose the Browse tab and navigate to "ImageGear for .NET v21\Bin" directory.
- Select ImageGear21.Formats.Dicom.dll, and click OK.
You should now have the ImageGear21.Formats.Dicom assembly listed under References in the Solution Explorer.
-
Next, add the DICOM using statement. Open the code for Form1.cs by right-clicking on the form and clicking View Code. At the top of the code add the following statement:
VB.NET Copy Code Imports ImageGear.Formats.DICOM
- Add the following statements in Form1_Load method right after the ImGearCommonFormats.Initialize() call:
VB.NET Copy Code ' Support for DICOM format ImGearFileFormats.Filters.Insert(0, ImGearDICOM.CreateDICOMFormat()) ' Set DICOM DIMSE control value for wide range of DICOM file detection. ImGearFileFormats.Filters.Get(ImGearFormats.DICOM).Parameters.GetByName("LoadDetectSkipDIMSE").Value = True ' Set LoadConcatenateRepeatedDE flag to true by default. ImGearFileFormats.Filters.Get(ImGearFormats.DICOM).Parameters.GetByName("LoadConcatenateRepeatedDE").Value = True
This will add the DICOM format to the ImageGear formats list. And now you are ready to compile and run the finished application supporting DICOM pages.
- To add support for DICOM documents, the following changes should be made:
- Under the File menu, add the Load Document menu item. Double-click it to create a handler.
- Copy the code from the Load Page menu handler for the Load Document menu handler.
- Add the following field to Form1:
VB.NET Copy Code Private igDocument As ImGearDocument
- In loadDocumentToolStripMenuItem_Click find the following code:
VB.NET Copy Code igPage = ImGearFileFormats.LoadPage(stream, 0)
VB.NET Copy Code igDocument = ImGearFileFormats.LoadDocument(stream, 0, 1) igPage = igDocument.Pages.Item(0)
It does the same thing, but using the ImGearDocument API.
Now you are ready to compile and run the finished application working with DICOM documents.
- To add support for loading/saving overlays, the following changes should be made:
- First, you need to add a reference to the ImageGear ART assembly (ImageGear21.Art).
- Next, add the corresponding using statement:
VB.NET Copy Code Imports ImageGear.ART
- Then declare the following member variable:
VB.NET Copy Code Private artPage As ImGearARTPage
- Modify the code of loadDocumentToolStripMenuItem_Click event handler, adding the following right before the imGearPageView1.Invalidate() call:
VB.NET Copy Code If (artPage IsNot Nothing) Then artPage.RemoveMarks() End If ' DICOM overlays artPage = ImGearDICOM.LoadOverlay(igPage) If (artPage Is Nothing) Then artPage = New ImGearARTPage() End If ImGearPageView1.Display.ARTPage = artPage
-
This will enable displaying overlays after loading the DICOM page.
- To enable saving overlays, the following statements should be added right before saving the page into file:
VB.NET Copy Code Dim rasterPage As ImGearRasterPage = ImGearPageView1.Display.Page ImGearDICOM.SaveOverlay(ImGearPageView1.Display.ARTPage, rasterPage)
- To add support for loading/saving presentation state, the following changes should be made:
- Repeat steps from points 5a - 5e, excluding:
VB.NET Copy Code artPage = ImGearDICOM.LoadOverlay(igPage)
- Declare the following member variable:
VB.NET Copy Code Private presStateOrigMetadata As ImGearMetadataHead
- Create "Load Presentation State" and "Save Presentation State" menu items under the File menu, then double-click them to create menu item handlers.
- Add the following code for the "Load Presentation State" menu item handler:
VB.NET Copy Code If igPage Is Nothing Or Not (TypeOf igPage Is ImGearRasterPage) Then Return End If Dim dlg As OpenFileDialog = New OpenFileDialog() dlg.Filter = "Presentation State (*.pre)|*.pre|All files (*.*)|*.*" dlg.Title = "Select Presentation State File" If dlg.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then Using fileContent As New FileStream(dlg.FileName, FileMode.Open, FileAccess.Read) Dim opts As New ImGearPresStateOptions() presStateOrigMetadata = ImGearDICOM.LoadPresState(fileContent, CType(igPage, ImGearRasterPage), ImGearPageView1.Display, opts) artPage = ImGearPageView1.Display.ARTPage ImGearPageView1.Update() End Using End If
- Add the following code for the "Save Presentation State" menu item handler:
VB.NET Copy Code Dim dlg As SaveFileDialog = New SaveFileDialog() dlg.Filter = "Presentation State (*.pre)|*.pre|All files (*.*)|*.*" dlg.Title = "Save Presentation State File" If dlg.ShowDialog() = System.Windows.Forms.DialogResult.OK Then Using fileContent As New FileStream(dlg.FileName, FileMode.Create) If TypeOf igPage Is ImGearRasterPage Then Dim opts As New ImGearPresStateOptions() Dim presStateMetadata As ImGearMetadataHead = ImGearDICOM.PreparePresStateMetadata(DirectCast(igPage, ImGearRasterPage), ImGearPageView1.Display, presStateOrigMetadata, opts) ' Note: The application can edit presStateMetadata here ImGearDICOM.SavePresState(fileContent, presStateMetadata) End If End Using End If
- And then add the following statement in the "Load Page" menu item handler's code, right before the imGearPageView1.Invalidate() statement:
VB.NET Copy Code ' Delete presStateOrigMetadata if any presStateOrigMetadata = Nothing
- Repeat steps from points 5a - 5e, excluding: