Beispiel #1
0
        public static void Write(DICOMBinaryWriter dw, DICOMIOSettings settings, DICOMObject d,
                                 bool isSequenceItem = false)
        {
            if (!isSequenceItem)
            {
                TransferSyntaxHelper.SetSyntax(d, settings.TransferSyntax);
            }

            for (var i = 0; i < d.Elements.Count; i++)
            {
                var el = d.Elements[i];
                var currentSettings = IsFileMetaGroup(el) ? settings.GetFileMetaSettings() : settings;
                if (GroupWriter.IsGroupHeader(el))
                {
                    var skip = GroupWriter.WriteGroup(dw, currentSettings, d, el);
                    i += skip;
                }
                else
                {
                    _logger.LogInformation($"Writing element ${el.Tag.CompleteID}");
                    try
                    {
                        DICOMElementWriter.Write(dw, currentSettings, el);
                    }
                    catch (Exception e)
                    {
                        _logger.LogError($"Error writing :  ${el.Tag.CompleteID}\n{e}");
                        throw e;
                    }
                }
            }
        }
 public static void Write(string filePath, DICOMWriteSettings settings, DICOMObject toWrite)
 {
     using (DICOMBinaryWriter dw = new DICOMBinaryWriter(filePath))
     {
         DICOMPreambleWriter.Write(dw);
         TransferSyntaxHelper.SetSyntax(toWrite, settings.TransferSyntax);
         DICOMObjectWriter.WriteObjectLittleEndian(dw, settings, toWrite);
     }
 }
Beispiel #3
0
 /// <summary>
 ///     Write DICOM file out (bytes) to a specified stream
 /// </summary>
 /// <param name="stream">the stream to which to write the file</param>
 /// <param name="settings">the write settings</param>
 /// <param name="toWrite">the object to write</param>
 public static void Write(Stream stream, DICOMWriteSettings settings, DICOMObject toWrite)
 {
     settings = settings ?? DICOMWriteSettings.Default();
     using (var dw = new DICOMBinaryWriter(stream))
     {
         DICOMPreambleWriter.Write(dw);
         TransferSyntaxHelper.SetSyntax(toWrite, settings.TransferSyntax);
         DICOMObjectWriter.Write(dw, settings, toWrite);
     }
 }
Beispiel #4
0
 /// <summary>
 /// Ignores the rule of writing metadata in explicit VR little endian and instead writes all elements with the passed in syntax
 /// </summary>
 /// <param name="dw"></param>
 /// <param name="settings"></param>
 /// <param name="d"></param>
 /// <param name="isSequenceItem"></param>
 public static void WriteSameSyntax(DICOMBinaryWriter dw, DICOMWriteSettings settings, DICOMObject d, bool isSequenceItem = false)
 {
     for (int i = 0; i < d.Elements.Count; i++)
     {
         IDICOMElement el = d.Elements[i];
         if (!isSequenceItem)
         {
             TransferSyntaxHelper.SetSyntax(d, settings.TransferSyntax);
         }
         if (GroupWriter.IsGroupHeader(el))
         {
             int skip = GroupWriter.WriteGroup(dw, settings, d, el);
             i += skip;
         }
         else
         {
             DICOMElementWriter.Write(dw, settings, el);
         }
     }
 }
 public static void Write(DICOMBinaryWriter dw, DICOMWriteSettings settings, DICOMObject d,
                          bool isSequenceItem = false)
 {
     for (var i = 0; i < d.Elements.Count; i++)
     {
         var el = d.Elements[i];
         if (!isSequenceItem)
         {
             TransferSyntaxHelper.SetSyntax(d, settings.TransferSyntax);
         }
         var currentSettings = IsFileMetaGroup(el) ? settings.GetFileMetaSettings() : settings;
         if (GroupWriter.IsGroupHeader(el))
         {
             var skip = GroupWriter.WriteGroup(dw, currentSettings, d, el);
             i += skip;
         }
         else
         {
             DICOMElementWriter.Write(dw, currentSettings, el);
         }
     }
 }