Пример #1
0
        /// <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));

            unchecked
            {
                foreach (Elements elements in items)
                {
                    writer.Write((short)0xFFFE);
                    writer.Write((short)0xE000);

                    // each nested element list can have its own SpecificCharacterSet,
                    // and it is valid for all nested elements, unless overridden again further down
                    SpecificCharacterSet scoped = encoding;
                    if (elements.Contains(t.SpecificCharacterSet))
                    {
                        scoped = new SpecificCharacterSet(elements[t.SpecificCharacterSet].Value);
                    }

                    uint size = 0;
                    // and account for the size of each child element
                    foreach (Element child in elements)
                    {
                        size += child.GetSize(syntax, scoped);
                    }
                    writer.Write(size);

                    foreach (Element child in elements)
                    {
                        child.Write(writer.BaseStream, syntax, scoped, options);
                    }
                }
            }
        }
Пример #2
0
        /// <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));
                }
            }
        }