ImageGear for .NET
Adding DICOM Support

Once the base of the tutorial application is completed, you can extend it with DICOM support using the following steps:

  1. First, you need to add a reference to the ImageGear for .NET DICOM Assembly.
    1. In the Solution Explorer, right-click on References, and choose Add Reference.
    2. Choose the Browse tab, 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.

  2. 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

     

  3. 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.

  4. To add support for DICOM documents, the following changes should be made:
    1. Under the File menu, add the Load Document menu item. Double-click it to create a handler.
    2. Copy the code from the Load Page menu handler for the Load Document menu handler.
    3. Add the following field to Form1:
      VB.NET
      Copy Code
      Private igDocument As ImGearDocument
    4. In loadDocumentToolStripMenuItem_Click find the following code:
      VB.NET
      Copy Code
      igPage = ImGearFileFormats.LoadPage(stream, 0)
      and replace it with:
      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.

  5. To add support for loading/saving overlays, the following changes should be made:
    1. First, you need to add a reference to the ImageGear ART assembly (ImageGear21.Art).
    2. Next, add the corresponding using statement:
      VB.NET
      Copy Code
      Imports ImageGear.ART
    3. Then declare the following member variable:
      VB.NET
      Copy Code
      Private artPage As ImGearARTPage
    4. 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
    5. This will enable displaying overlays after loading the DICOM page.

    6. 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)
  6. To add support for loading/saving presentation state, the following changes should be made:
    1. Repeat steps from points 5a - 5e, excluding:
      VB.NET
      Copy Code
      artPage = ImGearDICOM.LoadOverlay(igPage)
    2. Declare the following member variable:
      VB.NET
      Copy Code
      Private presStateOrigMetadata As ImGearMetadataHead
    3. Create "Load Presentation State" and "Save Presentation State" menu items under the File menu, then double-click them to create menu item handlers.
    4. 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
    5. 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
    6. 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

 

 


©2014. Accusoft Corporation. All Rights Reserved.

Send Feedback