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

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Post New Resource Bookmark and Share   

Convert text to image

Posted By:satyapriyanayak       Posted Date: August 17, 2013    Points: 40    Category:    URL: http://www.dotnetspark.com  

Here we will know how to convert the text to image. Here we have two controls button and textbox. When user enters any text to the textbox and clicks the button, then the text is converted to its corresponding image.

Note: - Here we need two namespaces.

using System.Drawing;

using System.Drawing.Imaging;


<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>Untitled Page</title>



    <form id="form1" runat="server">


     <asp:TextBox ID="TextBox1" runat="server" Width="200px"></asp:TextBox>

        <br /><br />


        <asp:Button ID="btnconvert" runat="server" Text="Convert to image"

            onclick="btnconvert_Click" />







using System;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.IO;

using System.Drawing;

using System.Drawing.Imaging;

public partial class _Default : System.Web.UI.Page


    protected void btnconvert_Click(object sender, EventArgs e)


        Bitmap bit1 = new Bitmap(200, 30, System.Drawing.Imaging.PixelFormat.Format64bppArgb);

        Graphics gph1 = Graphics.FromImage(bit1);

        string text;


        text = TextBox1.Text;

        gph1.DrawString(text, new Font("Arial", 12, FontStyle.Bold),

        new SolidBrush(Color.Red), new PointF(0.4F, 2.4F));

        Response.ContentType = "image/Jpeg";

        bit1.Save(Response.OutputStream, ImageFormat.Jpeg);






Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply

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