Monday, July 23, 2012

Converting text into an image format in c#...

just apply the code in ur application and see the changes and effects...

here is code snippet

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.IO;

namespace wer
{
public partial class WebForm1 : System.Web.UI.Page
{

Bitmap b = new Bitmap(1, 1);
Font f = new Font("Arial", 24);


protected void Page_Load(object sender, EventArgs e)
{

}

protected void btn_create_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "")
{ Response.Write("Please enter some text in the TextBox!!!"); }
else
{
Graphics graphics = Graphics.FromImage(b);
int width = (int)graphics.MeasureString(TextBox1.Text, f).Width;
int height = (int)graphics.MeasureString(TextBox1.Text, f).Height;
b = new Bitmap(b, new Size(width, height));
graphics = Graphics.FromImage(b);
graphics.Clear(Color.DarkBlue);
graphics.DrawString(TextBox1.Text, f, new SolidBrush(Color.White), 0, 0);
graphics.Flush();
b.Save("C:\\test.gif", System.Drawing.Imaging.ImageFormat.Gif);
Image1.Height = height;
Image1.Width = width;
  Image1.ImageUrl = "C:\\test.gif"; 
}
}
}
}
Happy coding ,.,.great day....

No comments: