/// <summary> /// Writes the element value to the stream. /// </summary> /// <param name="stream">The stream to write that positioned at the proper location to write.</param> /// <param name="syntax">The tranfer syntax to use if the value is binary.</param> /// <param name="encoding">The specific character set to use if the value is text.</param> /// <param name="options">The options used to encode tags.</param> protected override void WriteValueOnStream(Stream stream, string syntax, SpecificCharacterSet encoding, DataSetOptions options) { EndianBinaryWriter writer = new EndianBinaryWriter(stream, Syntax.GetEndian(syntax)); if (Syntax.CanEncapsulatePixelData(syntax)) { WriteEncapsulatedPixelData(writer); } else { if (vr == "OW") { short[] words = Value as short[]; foreach (short word in words) { writer.Write(word); } } else if (vr == "OB") { byte[] value = Value as byte[]; writer.Write((byte[])value); if (value.Length % 2 != 0) { writer.Write('\0'); } } else { throw new Exception(String.Format("Unexpected vr={0} in WriteValueOnStream", vr)); } } }
/// <summary> /// This method reads the value from the stream and sets the vm for string types /// </summary> /// <param name="stream">The stream to read the data from.</param> /// <param name="syntax">The transfer syntax used to interpret binary data.</param> /// <param name="encoding">The encoding to use to decode string data.</param> /// <param name="length">The length, in bytes, of the data to read.</param> /// <remarks>The stream is assumed to be positioned at the beginning of the encoded tag value.</remarks> protected override void ReadValueFromStream(Stream stream, string syntax, SpecificCharacterSet encoding, uint length) { this.length = length; EndianBinaryReader reader = new EndianBinaryReader(stream, Syntax.GetEndian(syntax)); if (length == 0xFFFFFFFF) { if (!Syntax.CanEncapsulatePixelData(syntax)) { throw new Exception(String.Format("Current syntax {0} does not support Encapsulated Pixel Data.", syntax, this.tag.Name)); } ReadEncapsulatedPixelData(reader); } else { ReadNativePixelData(reader); } }