private DicomDataset DeepClone_(DicomDataset dataset)
    {
      var ms = new MemoryStream();
      var target = new StreamByteTarget(ms);
      var writer = new DicomWriter(DicomTransferSyntax.ImplicitVRLittleEndian, DicomWriteOptions.Default, target);
      var walker = new DicomDatasetWalker(dataset);
      walker.Walk(writer);

      var clone = new DicomDataset();
      var reader = new DicomReader { IsExplicitVR = false };
      var byteSource = new ByteBufferByteSource(
        new MemoryByteBuffer(ms.ToArray()));
      reader.Read(byteSource, new DicomDatasetReaderObserver(clone));
      return clone;
    }
Beispiel #2
0
		public void Save(Stream stream) {
			if (Format == DicomFileFormat.ACRNEMA1 || Format == DicomFileFormat.ACRNEMA2)
				throw new DicomFileException(this, "Unable to save ACR-NEMA file");

			if (Format == DicomFileFormat.DICOM3NoFileMetaInfo) {
				// create file meta information from dataset
				FileMetaInfo = new DicomFileMetaInformation(Dataset);
			}

			OnSave();

			using (var target = new StreamByteTarget(stream)) {
				DicomFileWriter writer = new DicomFileWriter(DicomWriteOptions.Default);
				writer.Write(target, FileMetaInfo, Dataset);
			}
		}
Beispiel #3
0
        /// <summary>
        /// Asynchronously save DICOM file to stream.
        /// </summary>
        /// <param name="stream">Stream on which to save DICOM file.</param>
        /// <returns>Awaitable task.</returns>
        public async Task SaveAsync(Stream stream)
        {
            this.PreprocessFileMetaInformation();
            this.OnSave();

            var target = new StreamByteTarget(stream);
            var writer = new DicomFileWriter(DicomWriteOptions.Default);
            await writer.WriteAsync(target, this.FileMetaInfo, this.Dataset).ConfigureAwait(false);
        }
Beispiel #4
0
        /// <summary>
        /// Save DICOM file to stream.
        /// </summary>
        /// <param name="stream">Stream on which to save DICOM file.</param>
        public void Save(Stream stream)
        {
            this.PreprocessFileMetaInformation();
            this.OnSave();

            var target = new StreamByteTarget(stream);
            var writer = new DicomFileWriter(DicomWriteOptions.Default);
            writer.Write(target, this.FileMetaInfo, this.Dataset);
        }
Beispiel #5
0
        /// <summary>
        /// Asynchronously save DICOM file to stream.
        /// </summary>
        /// <param name="stream">Stream on which to save DICOM file.</param>
        /// <returns>Awaitable task.</returns>
        public async Task SaveAsync(Stream stream)
        {
            if (this.Format == DicomFileFormat.ACRNEMA1 || this.Format == DicomFileFormat.ACRNEMA2)
            {
                throw new DicomFileException(this, "Unable to save ACR-NEMA file");
            }

            if (this.Format == DicomFileFormat.DICOM3NoFileMetaInfo)
            {
                // create file meta information from dataset
                this.FileMetaInfo = new DicomFileMetaInformation(this.Dataset);
            }

            this.OnSave();

            var target = new StreamByteTarget(stream);
            var writer = new DicomFileWriter(DicomWriteOptions.Default);
            await writer.WriteAsync(target, this.FileMetaInfo, this.Dataset).ConfigureAwait(false);
        }