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, 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:
C# Copy Code using ImageGear.Formats.DICOM;
- Add the following statements in Form1 constructor after the ImGearCommonFormats.Initialize() call:
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.
- 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:
C# Copy Code private ImGearDocument imGearDocument = null;
- In loadDocumentToolStripMenuItem_Click find the following code:
C# Copy Code imGearPage = ImGearFileFormats.LoadPage(stream, 0);
C# Copy Code imGearDocument = ImGearFileFormats.LoadDocument(stream, 0, 1); imGearPage = 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.
- 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:
C# Copy Code using ImageGear.ART;
- Then declare the following member variable:
C# Copy Code private ImGearARTPage artPage;
- Modify the code of loadDocumentToolStripMenuItem_Click event handler, adding the following right before the imGearPageView1.Invalidate() call:
C# Copy Code if (artPage != null) { artPage.RemoveMarks(); } // DICOM overlays artPage = ImGearDICOM.LoadOverlay(imGearPage); if (artPage == null) { artPage = new ImGearARTPage(); } imGearPageView1.Display.ARTPage = artPage;
This will enable displaying overlays after loading the DICOM page.
- 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);
- To add support for loading/saving presentation state, the following changes should be made:
- Repeat steps from 5a - 5e, excluding:
C# Copy Code artPage = ImGearDICOM.LoadOverlay(imGearPage);
- Declare the following member variable:
C# Copy Code private ImGearMetadataHead presStateOrigMetadata;
- 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:
C# Copy Code if (!(imGearPage is ImGearRasterPage)) { return; } OpenFileDialog od = new OpenFileDialog(); od.Filter = "Presentation State (*.pre)|*.pre|All files (*.*)|*.*"; od.Title = "Select Presentation State File"; if (od.ShowDialog(this) == DialogResult.OK) { using (FileStream fileContent = new FileStream(od.FileName, FileMode.Open)) { ImGearPresStateOptions opts = new ImGearPresStateOptions(); presStateOrigMetadata = ImGearDICOM.LoadPresState(fileContent, (ImGearRasterPage)imGearPage, imGearPageView1.Display, opts); artPage = imGearPageView1.Display.ARTPage as ImGearARTPage; imGearPageView1.Update(); } }
- Add the following code for the "Save Presentation State" menu item handler:
C# Copy Code SaveFileDialog sd = new SaveFileDialog(); sd.Filter = "Presentation State (*.pre)|*.pre|All files (*.*)|*.*"; sd.Title = "Save Presentation State File"; if (sd.ShowDialog(this) == DialogResult.OK) { using (FileStream fileContent = new FileStream(sd.FileName, FileMode.Create)) { if (imGearPage is ImGearRasterPage) { ImGearPresStateOptions opts = new ImGearPresStateOptions(); ImGearMetadataHead presStateMetadata = ImGearDICOM.PreparePresStateMetadata((ImGearRasterPage)imGearPage, imGearPageView1.Display, presStateOrigMetadata, opts); // Note: The application can edit presStateMetadata here ImGearDICOM.SavePresState(fileContent, presStateMetadata); } } }
- 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;
- Repeat steps from 5a - 5e, excluding: