Exemplo n.º 1
0
        /// <summary>
        /// Reads a DICOM file from a path
        /// </summary>
        /// <param name="filePath">the path to the DICOM file</param>
        /// <returns>a DICOM object containing all elements</returns>
        public static DICOMObject Read(string filePath)
        {
            TransferSyntax       syntax;
            List <IDICOMElement> elements;

            using (DICOMBinaryReader dr = new DICOMBinaryReader(filePath))
            {
                DICOMPreambleReader.Read(dr);
                List <IDICOMElement> metaElements = ReadFileMetadata(dr, out syntax);
                elements = metaElements.Union(DICOMElementReader.ReadAllElements(dr, syntax)).ToList();
            }
            return(new DICOMObject(elements));
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Read the meta data from the DICOM object
        /// </summary>
        /// <param name="filePath">the path to the DICOM file</param>
        /// <returns>a DICOM object containing the metadata elements</returns>
        public static DICOMObject ReadFileMetadata(string filePath)
        {
            var enc    = StringEncoding.ISO_IR_192;
            var syntax = TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN;
            List <IDICOMElement> metaElements;

            using (var dr = new DICOMBinaryReader(filePath))
            {
                DICOMPreambleReader.Read(dr);
                metaElements = ReadFileMetadata(dr, ref syntax, ref enc);
            }
            return(new DICOMObject(metaElements));
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Reads a DICOM file from a byte array
        /// </summary>
        /// <param name="fileBytes">the bytes of the DICOM file</param>
        /// <returns>a DICOM object containing all elements</returns>
        public static DICOMObject Read(byte[] fileBytes,
                                       TransferSyntax trySyntax = TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN)
        {
            TransferSyntax       syntax = trySyntax; //Will keep if metadata doesn't exist
            List <IDICOMElement> elements;

            using (var dr = new DICOMBinaryReader(fileBytes))
            {
                DICOMPreambleReader.Read(dr);
                List <IDICOMElement> metaElements = ReadFileMetadata(dr, ref syntax);
                elements = metaElements.Concat(DICOMElementReader.ReadAllElements(dr, syntax)).ToList();
            }
            return(new DICOMObject(elements));
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Reads a DICOM file from a path
        /// </summary>
        /// <param name="filePath">the path to the DICOM file</param>
        /// <returns>a DICOM object containing all elements</returns>
        public static DICOMObject Read(string filePath,
                                       TransferSyntax trySyntax = TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN)
        {
            var syntax = trySyntax;
            List <IDICOMElement> elements;

            using (var dr = new DICOMBinaryReader(filePath))
            {
                DICOMPreambleReader.Read(dr);
                var metaElements = ReadFileMetadata(dr, ref syntax);
                elements = metaElements.Concat(DICOMElementReader.ReadAllElements(dr, syntax)).ToList();
            }
            return(new DICOMObject(elements));
        }
Exemplo n.º 5
0
 /// <summary>
 ///     Asynchronously reads a DICOM file from a path
 /// </summary>
 /// <param name="filePath">the path to the DICOM file</param>
 /// <returns>a DICOM object containing all elements</returns>
 public static async Task <DICOMObject> ReadAsync(string filePath,
                                                  TransferSyntax trySyntax = TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN)
 {
     return(await Task.Run(() =>
     {
         TransferSyntax syntax = trySyntax;
         List <IDICOMElement> elements;
         using (var dr = new DICOMBinaryReader(filePath))
         {
             DICOMPreambleReader.Read(dr);
             List <IDICOMElement> metaElements = ReadFileMetadata(dr, ref syntax);
             elements = metaElements.Concat(DICOMElementReader.ReadAllElements(dr, syntax)).ToList();
         }
         return new DICOMObject(elements);
     }));
 }