Wednesday, 15 June 2016

How To Convert Text Into Image In C# In Windows Application

6/15/2016 - By Pranav Singh 0

This article will show you how to convert text into image in c# In windows application. In this I have controlled textbox value into image.



Now we generate the button click event, and add the below code as shown below.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //how to convert text into image in c# In Windows Application
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("Please enter some value.");
            }
            else
            {
                pictureBox1.Image = DrawText(textBox1.Text);
            }
        }
        public Image ConvertImageToText(string textValue)
        {
            Image img = new Bitmap(200, 30, System.Drawing.Imaging.PixelFormat.Format64bppArgb);
            Graphics drawing = Graphics.FromImage(img);
            SizeF textSize = drawing.MeasureString(textValue, new Font("Arial", 20, FontStyle.Bold));
            img.Dispose();
            drawing.Dispose();
            img = new Bitmap((int)textSize.Width, (int)textSize.Height);
            drawing = Graphics.FromImage(img);
            drawing.Clear(Color.Black);
            Brush textBrush = new SolidBrush(Color.White);
            drawing.DrawString(text, new Font("Arial", 20, FontStyle.Bold), textBrush, new PointF(0.4F, 2.4F));
            drawing.Save();
            textBrush.Dispose();
            drawing.Dispose();
            return img;
        }
    }
}

In above code I have created a function whose return type is image and then bind the function to the picture box control by passing the textbox value as a method parameter. Now we have done run the application to check the output.

About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top