Convert text to image in

Posted by Satyapriyanayak under ASP.NET category on | Points: 40 | Views : 1567
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" "">

<html xmlns="">
<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);

Comments or Responses

Login to post response