public static void WriteTricolourTGA(string path, Colour colourLeft, Colour colourMiddle, Colour colourRight) { var width = 92; var height = 64; //byte r = 250; //byte g = 100; //byte b = 100; using (var file = File.Create(path)) { byte[] DeCompressed = new byte[] { 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; file.Write(DeCompressed, 0, DeCompressed.Length); file.WriteByte((byte)(width & 0xFF)); file.WriteByte((byte)((width & 0xFF) / 0xFF)); file.WriteByte((byte)(height & 0xFF)); file.WriteByte((byte)((height & 0xFF) / 0xFF)); file.WriteByte(24); file.WriteByte(0x0); for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { if (x < width / 3f) { WritePixel(file, colourLeft); } else if (x < 2 * width / 3f) { WritePixel(file, colourMiddle); } else { WritePixel(file, colourRight); } } //file.Write() } } }
private static void WritePixel(FileStream file, Colour colour) { file.WriteByte(colour.Blue); file.WriteByte(colour.Green); file.WriteByte(colour.Red); }