LEADTOOLS For .NET Class Library Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.28
Creating and Loading a Data Set

To create and load a Data Set from an existing DICOM file, you begin by creating an instance of the Leadtools.Dicom.DicomDataSet class. You can then use DicomDataSet.Load to load the Data Set.

At this point, you are ready to get information about the Data Set, traverse the Data Set, search for specific Modules or elements, get/set data values, add Modules or elements or delete Modules or elements.

As a short example, the code shown below does the following:

By comparing the displayed values for the Module number, Data Element Tag, and Value Representation to their respective default tables, you can determine which Module, element and Value Representation are present.

                  DicomDataSet dataSet;
                  int Count = 0;
                  DicomModule Module = null;
                  DicomElement Element = null;
                  string cs = string.Empty;
            
                  DicomEngine.Startup();
             /*  Create new DicomDataSet                                 */
            
                 dataSet = new DicomDataSet();
            
             /*  Load Dicom Data Set                                     */
                  dataSet.Load(ImagesPath.Path + "IMAGE2.dcm", 0);
             /*  Determine the number of modules in this dataset*/
                   Count = dataSet.ModuleCount;
                    
             /*  Find the first module on Level 0 of the Data Set tree   */
                     Module = dataSet.FindModuleByIndex(0);
                     if (Module != null)
                     {
                         Element = Module.Elements[0];
              /*  Print the information                                   */
                         string csFormat = "" +
                                  "This data set has {0:D} modules.\n" +
                                  "The type is: {1}\n" + 
                                  "The first module has {2:D} elements.\n " +
                                  "The second element of the first module has a length of {3:D},\n" + 
                                  "a tag {4:X}h and a VR {5:X}h";
            
             
                          MessageBox.Show(cs, "Notice");
                     }
                 else
                     MessageBox.Show( "Module is NULL", "Notice");
            
              /*  Release all resources used by the DICOM DataSet         */
                     dataSet.Dispose();