diff --git a/Program.cs b/Program.cs index 06a8bd0..24ecbc5 100644 --- a/Program.cs +++ b/Program.cs @@ -15,6 +15,8 @@ namespace task_78 return; writeFont(inFont, "font_print.bmp"); + Bitmap testBmp = new Bitmap(Image.FromFile("test.png")); + printToImage(testBmp, "test_print.bmp", inFont.chars.ToArray(), 128, 64); Console.ReadLine(); } @@ -50,6 +52,49 @@ namespace task_78 bmp.Save(path); Console.WriteLine("Bitmap saved!"); } + + /// + /// prints a single character on a bmp at a given destination + /// + /// + /// + /// + /// + /// + private static Bitmap printToImage(Bitmap bmp, Font.Char c, int x, int y) { + for (int xx = 0; xx < c.w; xx++) { + for (int yy = 0; yy < c.h; yy++) { + // Print every single pixel of given character + try { + // respect the offset here, x = target location of character, xx = current iteration of character pixel. + int code = c.data[xx, yy]; + if (code != 6) + bmp.SetPixel(x + xx, y + yy, Color.FromArgb(255, code, code, code)); + } catch (Exception e) { + Console.WriteLine(e.Message); + } + } + } + return bmp; + } + + /// + /// Prints a given array of chars into a bitmap, then writes it to given destination file. + /// + /// + /// + /// + /// + /// + public static void printToImage(Bitmap source, string destination, Font.Char[] chars, int x, int y) { + int shift = 0; + foreach(var c in chars) { + source = printToImage(source, c, x + shift, y); + shift += c.w + 1; + } + source.Save(destination); + Console.WriteLine("printed a total of " + chars.Length + " characters to bmp, saved as " + destination); + } } public class Font { diff --git a/task_78.csproj b/task_78.csproj index 112dccf..426151a 100644 --- a/task_78.csproj +++ b/task_78.csproj @@ -45,7 +45,6 @@ - @@ -55,6 +54,11 @@ Always + + + Always + +