internal void WriteSecondHeader(BitWriter writer, int id) { // compute the minimum number of bytes necessary to encode the handle var handleBytes = BitConverter.GetBytes(HandleOrOffset); if (BitConverter.IsLittleEndian) { Array.Reverse(handleBytes); } var bytesList = new List <byte>(handleBytes); while (bytesList.Count > 0 && bytesList[0] == 0) { bytesList.RemoveAt(0); } if (bytesList.Count == 0) { // ensure there's a least one byte bytesList.Add(0); } writer.Write_RC((byte)bytesList.Count); writer.Write_RC((byte)id); writer.WriteBytes(bytesList.ToArray()); }
internal void Write(BitWriter writer, int offsetAdjustment) { var startOffset = writer.Position; writer.WriteBytes(StartSentinel); var imageCount = 0; if (HeaderData?.Length > 0) { imageCount++; } if (BmpData?.Length > 0) { imageCount++; } if (WmfData?.Length > 0) { imageCount++; } var imageControlByteCount = imageCount * (1 + 4 + 4) + // each set of data writes a byte and two ints 1; // `imageCount` below var overallSize = imageControlByteCount + (HeaderData?.Length ?? 0) + (BmpData?.Length ?? 0) + (WmfData?.Length ?? 0); writer.Write_RL(overallSize); writer.Write_RC((byte)imageCount); if (HeaderData?.Length > 0) { writer.Write_RC(1); writer.Write_RL(writer.Position - startOffset + offsetAdjustment); // start writer.Write_RL(HeaderData.Length); } if (BmpData?.Length > 0) { writer.Write_RC(2); writer.Write_RL(writer.Position - startOffset + offsetAdjustment); // start writer.Write_RL(BmpData.Length); } if (WmfData?.Length > 0) { writer.Write_RC(3); writer.Write_RL(writer.Position - startOffset + offsetAdjustment); // start writer.Write_RL(WmfData.Length); } writer.WriteBytes(EndSentinel); }