Convert Text to Image Using C#

We can easily convert text to image in C# using System.Drawing Namespace. Here this article will guide you how to create a bitmap image from text. it’s using Graphics property of System.Drawing namespace to convert Text to Image. The Graphics class provides methods for drawing to display device.

In this article, you will see a method Named ConvertTextToImage(string txt, string fontname, int fontsize, Color bgcolor, Color fcolor, int width, int height)  is responsible to return bitmap image on the basis of Text, fontname and fontsize, backcolor and forecolor with apporpriate width and height.

Take a look how to create this function

[sourcecode language=”csharp”] class ImageUtils
public static Bitmap ConvertTextToImage(string txt, string fontname, int fontsize, Color bgcolor, Color fcolor, int width, int Height)
Bitmap bmp = new Bitmap(width, Height);
using (Graphics graphics = Graphics.FromImage(bmp))

Font font = new Font(fontname, fontsize);
graphics.FillRectangle(new SolidBrush(bgcolor), 0, 0, bmp.Width, bmp.Height);
graphics.DrawString(txt, font, new SolidBrush(fcolor), 0, 0);
return bmp;

you can use given method in your program after just adding class Imageutils, take a look how

[sourcecode language=”csharp”] <pre> private void btnconvert_Click(object sender, EventArgs e)
// Calling ConvertTextToImage function
picbox.Image = ImageUtils.ConvertTextToImage(textBox1.Text, "Bookman Old Style", 10,
Color.Yellow, Color.Red, textBox1.Width, textBox1.Height);

Take a look how it call in project

How to Call Function in your Project

Take a look after using function and giving appropriate parameter how it look like after compiling
How it looks after Compiling

Now Download Sourcecode for more details and keep enjoy with changing text to  image.
ClickMe  to Download SourceCode.  🙂

3 thoughts on “Convert Text to Image Using C#”

  1. Coruscate says:

    i can not download means give me error like Not Found

  2. Mahesh says:

    can you please send the code for image to text converter

    1. Ravi Ranjan Kumar says:

      Sorry Mahesh! you have to work by yourself. In case of any query or confusion you can revert back. Have some hint – you can convert image to Memory Stream and then from Memory Stream to Base64String.

Leave a Reply