Esempio n. 1
0
        /** <summary> Writes the object data. </summary> */
        protected void Write(BinaryWriter writer)
        {
            // Write the header
            WriteHeader(writer);

            // Write the string table entries
            stringTable.Write(writer);
            // Write the group info
            if (HasGroupInfo)
            {
                groupInfo.Write(writer);
            }

            // Write the optional section
            WriteOptional(writer);

            long imageDirectoryPosition = writer.BaseStream.Position;

            if (HasGraphics)
            {
                // Write the image directory and graphics data
                imageDirectory.Write(writer);
                graphicsData.Write(writer);

                // Rewrite the image directory after the image addresses are known
                long finalPosition = writer.BaseStream.Position;
                writer.BaseStream.Position = imageDirectoryPosition;
                imageDirectory.Write(writer);

                // Set the position to the end of the file so the file size is known
                writer.BaseStream.Position = finalPosition;
            }
        }
Esempio n. 2
0
        //============ STATIC ============
        #region Static

        /** <summary> Saves the graphics directory to the specified file path. </summary> */
        public void Save(string path)
        {
            BinaryWriter writer = new BinaryWriter(new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write));
            long         imageDirectoryPosition = writer.BaseStream.Position;

            // Write the image directory and graphics data
            imageDirectory.Write(writer);
            Write(writer);

            // Rewrite the image directory after the image addresses are known
            writer.BaseStream.Position = imageDirectoryPosition;
            imageDirectory.Write(writer);
            writer.Close();
        }
Esempio n. 3
0
        //=========== READING ============
        #region Reading

        /** <summary> Saves the palette image to the specified file path. </summary> */
        public void Save(string path)
        {
            BinaryWriter   writer         = new BinaryWriter(new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write));
            ImageDirectory imageDirectory = new ImageDirectory();
            GraphicsData   graphicsData   = new GraphicsData(imageDirectory);

            graphicsData.Add(this);

            long imageDirectoryPosition = writer.BaseStream.Position;

            imageDirectory.Write(writer);
            graphicsData.Write(writer);
            writer.BaseStream.Position = imageDirectoryPosition;
            imageDirectory.Write(writer);

            writer.Close();
        }