/// <summary> /// Draws Text with font in Bitmap and returns /// </summary> /// <param name="fontId"></param> /// <param name="text"></param> /// <returns></returns> public static Bitmap DrawText(int fontId, string text) { ASCIIFont font = ASCIIFont.GetFixed(fontId); Bitmap result = new Bitmap(font.GetWidth(text) + 2, font.Height + 2); int dx = 2; int dy = font.Height + 2; using (Graphics graph = Graphics.FromImage(result)) { for (int i = 0; i < text.Length; ++i) { Bitmap bmp = font.GetBitmap(text[i]); graph.DrawImage(bmp, dx, dy - bmp.Height); dx += bmp.Width; } } return(result); }
/// <summary> /// Draws Text with font in Bitmap and returns /// </summary> /// <param name="fontId"></param> /// <param name="text"></param> /// <returns></returns> public static Bitmap DrawText(int fontId, string text) { ASCIIFont font = ASCIIFont.GetFixed(fontId); var result = new Bitmap(font.GetWidth(text) + 2, font.Height + 2); int dx = 2; int dy = font.Height + 2; using (Graphics graph = Graphics.FromImage(result)) { foreach (var character in text) { Bitmap bmp = font.GetBitmap(character); graph.DrawImage(bmp, dx, dy - bmp.Height); dx += bmp.Width; } } return(result); }