Exemplo n.º 1
0
        static void Test(string relativePath)
        {
            try
            {
                using (var stream = OpenRead(relativePath))
                {
                    var input = new BufferedStreamReader(stream);
                    if (DicomFileFormat.TryReadHeader(input, out DicomFileMetaInformation fileMetaInformation))
                    {
                        Console.WriteLine($"SOPClassUID = {fileMetaInformation.MediaStorageSOPClassUID}");
                        Console.WriteLine($"TransferSyntax = {(DicomUID)fileMetaInformation.TransferSyntaxUID}");

                        Console.WriteLine(JsonSerializer.Serialize(fileMetaInformation, new JsonSerializerOptions
                        {
                            WriteIndented = true
                        }));

                        var xmlOutputPath = $"{stream.Name}.xml";
                        Console.WriteLine($"Writing dataset to {xmlOutputPath}");

                        var dataSet = new XElement("DicomDataSet");
                        dataSet.SetAttributeValue("Source", stream.Name);
                        var dataSetReader = DicomStreamReader.Create(input, fileMetaInformation.TransferSyntaxUID);
                        dataSetReader.ReadDataSet(dataSet, new DicomToXmlConverter());
                        dataSet.Save(xmlOutputPath);
                    }
                    else
                    {
                        Console.WriteLine($"Skipped");
                    }
                }
            }
            catch (Exception error)
            {
                Console.WriteLine($"ERROR: {error.Message}");
            }
        }