/// <summary> /// Loads a dicom file, stopping at a certain tag /// </summary> /// <param name="file">Filename</param> /// <param name="stopTag">Tag to stop parsing at</param> /// <param name="options">DICOM read options</param> public DicomReadStatus Load(String file, DicomTag stopTag, DicomReadOptions options) { using (FileStream fs = File.OpenRead(file)) { fs.Seek(128, SeekOrigin.Begin); CheckFileHeader(fs); DicomStreamReader dsr = new DicomStreamReader(fs); _metainfo = new DcmFileMetaInfo(); dsr.Dataset = _metainfo; dsr.Read(DcmFileMetaInfo.StopTag, options | DicomReadOptions.FileMetaInfoOnly); if (_metainfo.TransferSyntax.IsDeflate) { MemoryStream ms = StreamUtility.Deflate(fs, false); dsr = new DicomStreamReader(ms); } _dataset = new DcmDataset(_metainfo.TransferSyntax); dsr.Dataset = _dataset; DicomReadStatus status = dsr.Read(stopTag, options); fs.Close(); return(status); } }
/// <summary> /// Initializes new DICOM file format from dataset /// </summary> /// <param name="dataset">Dataset</param> public DicomFileFormat(DcmDataset dataset) { _metainfo = new DcmFileMetaInfo(); _metainfo.FileMetaInformationVersion = DcmFileMetaInfo.Version; _metainfo.MediaStorageSOPClassUID = dataset.GetUID(DicomTags.SOPClassUID); _metainfo.MediaStorageSOPInstanceUID = dataset.GetUID(DicomTags.SOPInstanceUID); _metainfo.TransferSyntax = dataset.InternalTransferSyntax; _metainfo.ImplementationClassUID = Implementation.ClassUID; _metainfo.ImplementationVersionName = Implementation.Version; _metainfo.SourceApplicationEntityTitle = ""; _dataset = dataset; }
/// <summary> /// Gets the file meta information from a DICOM file /// </summary> /// <param name="file">Filename</param> /// <returns>File meta information</returns> public static DcmFileMetaInfo LoadFileMetaInfo(String file) { using (FileStream fs = File.OpenRead(file)) { fs.Seek(128, SeekOrigin.Begin); CheckFileHeader(fs); DicomStreamReader dsr = new DicomStreamReader(fs); DcmFileMetaInfo metainfo = new DcmFileMetaInfo(); dsr.Dataset = metainfo; dsr.Read(DcmFileMetaInfo.StopTag, DicomReadOptions.Default | DicomReadOptions.FileMetaInfoOnly); fs.Close(); return(metainfo); } }
/// <summary> /// Gets file stream starting at DICOM dataset /// </summary> /// <param name="file">Filename</param> /// <returns>File stream</returns> public static FileStream GetDatasetStream(String file) { FileStream fs = File.OpenRead(file); fs.Seek(128, SeekOrigin.Begin); CheckFileHeader(fs); DicomStreamReader dsr = new DicomStreamReader(fs); DcmFileMetaInfo metainfo = new DcmFileMetaInfo(); dsr.Dataset = metainfo; if (dsr.Read(DcmFileMetaInfo.StopTag, DicomReadOptions.Default | DicomReadOptions.FileMetaInfoOnly) == DicomReadStatus.Success && fs.Position < fs.Length) { return(fs); } fs.Close(); return(null); }
/// <summary> /// Gets file stream starting at DICOM dataset /// </summary> /// <param name="file">Filename</param> /// <param name="useIsoStore">Get dataset from isolated store</param> /// <returns>File stream</returns> public static FileStream GetDatasetStream(String file, bool useIsoStore = false) { if (useIsoStore) { using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { var fs = store.OpenFile(file, FileMode.Open, FileAccess.Read); fs.Seek(128, SeekOrigin.Begin); CheckFileHeader(fs); DicomStreamReader dsr = new DicomStreamReader(fs); DcmFileMetaInfo metainfo = new DcmFileMetaInfo(); dsr.Dataset = metainfo; if ( dsr.Read(DcmFileMetaInfo.StopTag, DicomReadOptions.Default | DicomReadOptions.FileMetaInfoOnly) == DicomReadStatus.Success && fs.Position < fs.Length) { return(fs); } fs.Close(); return(null); } } else { FileStream fs = File.OpenRead(file); fs.Seek(128, SeekOrigin.Begin); CheckFileHeader(fs); DicomStreamReader dsr = new DicomStreamReader(fs); DcmFileMetaInfo metainfo = new DcmFileMetaInfo(); dsr.Dataset = metainfo; if (dsr.Read(DcmFileMetaInfo.StopTag, DicomReadOptions.Default | DicomReadOptions.FileMetaInfoOnly) == DicomReadStatus.Success && fs.Position < fs.Length) { return(fs); } fs.Close(); return(null); } }
/// <summary> /// Gets the file meta information from a DICOM file /// </summary> /// <param name="file">Filename</param> /// <param name="useIsoStore">Load file from isolated storage</param> /// <returns>File meta information</returns> public static DcmFileMetaInfo LoadFileMetaInfo(String file, bool useIsoStore = false) { if (useIsoStore) { using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var fs = store.OpenFile(file, FileMode.Open, FileAccess.Read)) { fs.Seek(128, SeekOrigin.Begin); if (!CheckFileHeader(fs)) { return(null); } DicomStreamReader dsr = new DicomStreamReader(fs); DcmFileMetaInfo metainfo = new DcmFileMetaInfo(); dsr.Dataset = metainfo; dsr.Read(DcmFileMetaInfo.StopTag, DicomReadOptions.Default | DicomReadOptions.FileMetaInfoOnly); fs.Close(); return(metainfo); } } } else { using (var fs = File.OpenRead(file)) { fs.Seek(128, SeekOrigin.Begin); CheckFileHeader(fs); DicomStreamReader dsr = new DicomStreamReader(fs); DcmFileMetaInfo metainfo = new DcmFileMetaInfo(); dsr.Dataset = metainfo; dsr.Read(DcmFileMetaInfo.StopTag, DicomReadOptions.Default | DicomReadOptions.FileMetaInfoOnly); fs.Close(); return(metainfo); } } }
/// <summary> /// Gets the file meta information from a DICOM file /// </summary> /// <param name="file">Filename</param> /// <returns>File meta information</returns> public static DcmFileMetaInfo LoadFileMetaInfo(String file) { using (FileStream fs = File.OpenRead(file)) { fs.Seek(128, SeekOrigin.Begin); CheckFileHeader(fs); DicomStreamReader dsr = new DicomStreamReader(fs); DcmFileMetaInfo metainfo = new DcmFileMetaInfo(); dsr.Dataset = metainfo; dsr.Read(DcmFileMetaInfo.StopTag, DicomReadOptions.Default | DicomReadOptions.FileMetaInfoOnly); fs.Close(); return metainfo; } }
/// <summary> /// Gets file stream starting at DICOM dataset /// </summary> /// <param name="file">Filename</param> /// <returns>File stream</returns> public static FileStream GetDatasetStream(String file) { FileStream fs = File.OpenRead(file); fs.Seek(128, SeekOrigin.Begin); CheckFileHeader(fs); DicomStreamReader dsr = new DicomStreamReader(fs); DcmFileMetaInfo metainfo = new DcmFileMetaInfo(); dsr.Dataset = metainfo; if (dsr.Read(DcmFileMetaInfo.StopTag, DicomReadOptions.Default | DicomReadOptions.FileMetaInfoOnly) == DicomReadStatus.Success && fs.Position < fs.Length) { return fs; } fs.Close(); return null; }
/// <summary> /// Loads a dicom file, stopping at a certain tag /// </summary> /// <param name="file">Filename</param> /// <param name="stopTag">Tag to stop parsing at</param> /// <param name="options">DICOM read options</param> public DicomReadStatus Load(String file, DicomTag stopTag, DicomReadOptions options) { using (FileStream fs = File.OpenRead(file)) { fs.Seek(128, SeekOrigin.Begin); CheckFileHeader(fs); DicomStreamReader dsr = new DicomStreamReader(fs); _metainfo = new DcmFileMetaInfo(); dsr.Dataset = _metainfo; dsr.Read(DcmFileMetaInfo.StopTag, options | DicomReadOptions.FileMetaInfoOnly); if (_metainfo.TransferSyntax.IsDeflate) { MemoryStream ms = StreamUtility.Deflate(fs, false); dsr = new DicomStreamReader(ms); } _dataset = new DcmDataset(_metainfo.TransferSyntax); dsr.Dataset = _dataset; DicomReadStatus status = dsr.Read(stopTag, options); fs.Close(); return status; } }
/// <summary> /// Gets the file meta information from a DICOM file /// </summary> /// <param name="file">Filename</param> /// <param name="useIsoStore">Load file from isolated storage</param> /// <returns>File meta information</returns> public static DcmFileMetaInfo LoadFileMetaInfo(String file, bool useIsoStore = false) { if (useIsoStore) { using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { using (var fs = store.OpenFile(file, FileMode.Open, FileAccess.Read)) { fs.Seek(128, SeekOrigin.Begin); if (!CheckFileHeader(fs)) return null; DicomStreamReader dsr = new DicomStreamReader(fs); DcmFileMetaInfo metainfo = new DcmFileMetaInfo(); dsr.Dataset = metainfo; dsr.Read(DcmFileMetaInfo.StopTag, DicomReadOptions.Default | DicomReadOptions.FileMetaInfoOnly); fs.Close(); return metainfo; } } } else { using (var fs = File.OpenRead(file)) { fs.Seek(128, SeekOrigin.Begin); CheckFileHeader(fs); DicomStreamReader dsr = new DicomStreamReader(fs); DcmFileMetaInfo metainfo = new DcmFileMetaInfo(); dsr.Dataset = metainfo; dsr.Read(DcmFileMetaInfo.StopTag, DicomReadOptions.Default | DicomReadOptions.FileMetaInfoOnly); fs.Close(); return metainfo; } } }
/// <summary> /// Gets file stream starting at DICOM dataset /// </summary> /// <param name="file">Filename</param> /// <param name="useIsoStore">Get dataset from isolated store</param> /// <returns>File stream</returns> public static FileStream GetDatasetStream(String file, bool useIsoStore = false) { if (useIsoStore) { using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { var fs = store.OpenFile(file, FileMode.Open, FileAccess.Read); fs.Seek(128, SeekOrigin.Begin); CheckFileHeader(fs); DicomStreamReader dsr = new DicomStreamReader(fs); DcmFileMetaInfo metainfo = new DcmFileMetaInfo(); dsr.Dataset = metainfo; if ( dsr.Read(DcmFileMetaInfo.StopTag, DicomReadOptions.Default | DicomReadOptions.FileMetaInfoOnly) == DicomReadStatus.Success && fs.Position < fs.Length) { return fs; } fs.Close(); return null; } } else { FileStream fs = File.OpenRead(file); fs.Seek(128, SeekOrigin.Begin); CheckFileHeader(fs); DicomStreamReader dsr = new DicomStreamReader(fs); DcmFileMetaInfo metainfo = new DcmFileMetaInfo(); dsr.Dataset = metainfo; if (dsr.Read(DcmFileMetaInfo.StopTag, DicomReadOptions.Default | DicomReadOptions.FileMetaInfoOnly) == DicomReadStatus.Success && fs.Position < fs.Length) { return fs; } fs.Close(); return null; } }
/// <summary> /// Loads a dicom file from a stream, stopping at a certain tag /// </summary> /// <param name="stream">Stream containing DICOM file</param> /// <param name="stopTag">Tag to stop parsing at</param> /// <param name="options">DICOM read options</param> public DicomReadStatus Load(Stream stream, DicomTag stopTag, DicomReadOptions options) { stream.Seek(128, SeekOrigin.Begin); CheckFileHeader(stream); DicomStreamReader dsr = new DicomStreamReader(stream); _metainfo = new DcmFileMetaInfo(); dsr.Dataset = _metainfo; dsr.Read(DcmFileMetaInfo.StopTag, options | DicomReadOptions.FileMetaInfoOnly); if (_metainfo.TransferSyntax.IsDeflate) { MemoryStream ms = StreamUtility.Deflate(stream, false); dsr = new DicomStreamReader(ms); } _dataset = new DcmDataset(_metainfo.TransferSyntax); dsr.Dataset = _dataset; DicomReadStatus status = dsr.Read(stopTag, options); return status; }
/// <summary> /// Loads the meta information from a DICOM file in a stream. /// Note that the caller is expected to dispose of the stream after usage. /// </summary> /// <param name="stream">The stream fontaining the DICOM file</param> /// <returns>File meta information</returns> public static DcmFileMetaInfo LoadFileMetaInfo(Stream stream) { stream.Seek(128, SeekOrigin.Begin); CheckFileHeader(stream); DicomStreamReader dsr = new DicomStreamReader(stream); DcmFileMetaInfo metainfo = new DcmFileMetaInfo(); dsr.Dataset = metainfo; dsr.Read(DcmFileMetaInfo.StopTag, DicomReadOptions.Default | DicomReadOptions.FileMetaInfoOnly); return metainfo; }