/**<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); if (HasGraphics) { long imageDirectoryPosition = writer.BaseStream.Position; // 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; } }
//============ 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(); }
//============ SAVING ============ #region Saving /**<summary>Saves the graphics directory to the specified stream.</summary>*/ public void Save(Stream stream) { BinaryWriter writer = new BinaryWriter(stream); long imageDirectoryPosition = stream.Position; // Write the image directory and graphics data imageDirectory.Write(writer); Write(writer); long endPosition = stream.Position; // Rewrite the image directory after the image addresses are known stream.Position = imageDirectoryPosition; imageDirectory.Write(writer); stream.Position = endPosition; }