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
    3. 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 Window1.xaml.cs. At the top of the code add the following statement:

    C#
    Copy Code
    using ImageGear.Formats.DICOM;
  3. Add the following statements in Window1 constructor:
    C#
    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. Add the following field to Window1:
      C#
      Copy Code
      private ImGearDocument igDocument;
    2. In OpenExecuted find the following code:
      C#
      Copy Code
      igPage = ImGearFileFormats.LoadPage(stream, 0);
      and replace it with:
      C#
      Copy Code
      igDocument = ImGearFileFormats.LoadDocument(stream, 0, 1);
      igPage = imGearDocument.Pages[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.dll).
    2. Next, add the corresponding using statement:
      C#
      Copy Code
      using ImageGear.ART;
    3. Modify the code of the OpenExecuted in "if (null != igPage && null != igPage.DIB && !igPage.DIB.IsEmpty())" block to be:
      imGearPageView1.Update() call:
      C#
      Copy Code
      // DICOM overlays
      ImGearARTPage artPage = ImGearDICOM.LoadOverlay(igPage, false);
        if (artPage == null)
        {
         artPage = new ImGearARTPage();
        }
        artGUI.Page = artPage;
        
        // Create a new page display
        igPageDisplay = new ImGearPresentationPageDisplay(igPage, artPage);
      // Associate page with the page view
        imGearPageView1.Display = igPageDisplay;
      // Cause the page view to update
      imGearPageView1.Update();

      This will enable displaying overlays after loading the DICOM page.

    4. To enable saving overlays, the following statement should be added right before saving the page into file:
      C#
      Copy Code
      ImGearDICOM.SaveOverlay((imGearPageView1.Display.ARTPage as ImGearARTPage), imGearPageView1.Display.Page as ImGearRasterPage);
  6. To add support for loading/saving presentation state, the following changes should be made:
    1. Repeat steps from points 5a - 5e.
    2. Declare the following member variables:
      C#
      Copy Code
      private ImGearMetadataHead presStateOrigMetadata;
      public static RoutedCommand LoadPresStateCmd = new RoutedCommand();
      public static RoutedCommand SavePresStateCmd = new RoutedCommand();
    3. Create "Load Presentation State" and "Save Presentation State" menu items under the File menu in Window1.xaml file.
      XAML
      Copy Code
      <MenuItem Name="mnuLoadPresState" Header="_Load Presentation State" Command="{x:Static custom:Window1.LoadPresStateCmd}"/>
      <MenuItem Name="mnuSavePresState" Header="_Save Presentation State" Command="{x:Static custom:Window1.SavePresStateCmd}"/>
    4. Add command bindings under the <Window.CommandBindings> section of the Window1.xaml file:
      XAML
      Copy Code
      <CommandBinding
            Command="{x:Static custom:Window1.LoadPresStateCmd}"
            CanExecute="CanExectutePageAvailable"
            Executed="LoadPresState"/>
      <CommandBinding
            Command="{x:Static custom:Window1.SavePresStateCmd}"
            CanExecute="CanExectutePageAvailable"
            Executed="SavePresState"/>
      Right-click over each entry and click 'Navigate to Even Handler' to add the C# handler to the Window1 class in the .xaml.cs file.
    5. Add the following code for the "Load Presentation State" menu item handler:
      C#
      Copy Code
      if (!(igPage is ImGearRasterPage))
       {
        return;
       }
       System.Windows.Forms.OpenFileDialog od = new System.Windows.Forms.OpenFileDialog();
       od.Filter = "Presentation State (*.pre)|*.pre|All files (*.*)|*.*";
       od.Title = "Select Presentation State File";
       if (od.ShowDialog() == System.Windows.Forms.DialogResult.OK)
       {
        using (FileStream fileContent = new FileStream(od.FileName, FileMode.Open))
        {
         ImGearPresStateOptions opts = new ImGearPresStateOptions();
         presStateOrigMetadata = ImGearDICOM.LoadPresState(fileContent, (ImGearRasterPage)igPage, imGearPageView1.Display, opts);
         imGearPageView1.Update();
        }
       }
    6. Add the following code for the "Save Presentation State" menu item handler:
      C#
      Copy Code
      System.Windows.Forms.SaveFileDialog sd = new System.Windows.Forms.SaveFileDialog ();
      sd.Filter = "Presentation State (*.pre)|*.pre|All files (*.*)|*.*";
      sd.Title = "Save Presentation State File";
      if (sd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
      {
       using (FileStream fileContent = new FileStream(sd.FileName, FileMode.Create))
       {
        if (igPage is ImGearRasterPage)
        {
         ImGearPresStateOptions opts = new ImGearPresStateOptions();
         ImGearMetadataHead presStateMetadata = ImGearDICOM.PreparePresStateMetadata((ImGearRasterPage)igPage,
       imGearPageView1.Display,
       presStateOrigMetadata, opts);
         // Note: The application can edit presStateMetadata here
         ImGearDICOM.SavePresState(fileContent, presStateMetadata);
        }
       }
      }
    7. And then add the following statement in the "Load Page" menu item handler's code, right before the imGearPageView1.Invalidate() statement:
      C#
      Copy Code
        // Delete presStateOrigMetadata if any
        presStateOrigMetadata = null;

 

 


©2014. Accusoft Corporation. All Rights Reserved.

Send Feedback