C#

Convert Text into Image with C#

Let’s see how we can convert text into an image using C#:

1
2
3
4
5
6
7
8
9
10
11
12
public Image DrawText(String text)
{
	Image img = new Bitmap(64, 64);
	Graphics drawing = Graphics.FromImage(img);
	drawing.Clear(Color.Yellow);
	Brush textBrush = new SolidBrush(Color.Black);
	drawing.DrawString(text, new Font(new FontFamily("Trebuchet MS"), 12f), textBrush, 0, 0);
	drawing.Save();
	textBrush.Dispose();
	drawing.Dispose();
	return img;
}