.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Convert Text to Image

Posted By:Ravi Ranjan Kumar       Posted Date: June 07, 2011    Points: 200    Category: C#    URL: http://www.dotnetspark.com  

This Article enable you to learn how to Convert Text to Image using C#

We can easily convert text to image in C# by using  System.Drawing  namespace. Here this tips will guide you how to create bitmap image from text. It's using Graphics property  of System.Drawing  namespace to convert text to bitmap image and place the image in a picture box. The Graphics class provides methods for drawing to the display device.

In this article you will see a Method 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 of Image with appropriate width and height.

Take a look how to create this function

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

 private void btnconvert_Click(object sender, EventArgs e)
            // Calling ConvertTextToImage function with appropriate parameter, you can call as per your requirement 
            picbox.Image = ImageUtils.ConvertTextToImage(textBox1.Text, "Bookman Old Style", 10, 
                Color.Yellow, Color.Red, textBox1.Width, textBox1.Height);
Take a look in Image  

Take a look how it Convert Text to Image 

Now Download Source Code for getting more details and Keep Enjoying Coding..  :)

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend