We can Convert text to image in c# using System.Drawing namespace.
Here we create a bitmap image and use its Graphics property to convert text passed to image and place the image in a picture box.
private void TextToImage() { Color BackColor = Color.White; String FontName = "Times New Roman"; int FontSize = 25; int Height = 50; int Width = 300; <span style="color: rgb(56, 118, 29);"> //creating bitmap image <span style="color: rgb(0, 0, 0);">Bitmap </span></span>bitmap = new Bitmap(Width, Height); <span style="color: rgb(56, 118, 29);">//FromImage method creates a new Graphics from the specified Image.</span> Graphics graphics = Graphics.FromImage(bitmap); Color color = Color.Gray; Font font = new Font(FontName, FontSize); SolidBrush BrushBackColor = new SolidBrush(BackColor); Pen BorderPen = new Pen(color); Rectangle displayRectangle = new Rectangle(new Point(0, 0), new Size(Width - 1, Height - 1)); <span style="color: rgb(56, 118, 29);">//Drawing a rectangle and filling the background as white <span style="color: rgb(0, 0, 0);">graphics</span></span>.FillRectangle(BrushBackColor, displayRectangle); graphics.DrawRectangle(BorderPen, displayRectangle); <span style="color: rgb(56, 118, 29);"> //giving the font and color to the string passed</span> graphics.DrawString(txtEnter.Text,font,Brushes.Red, 0, 0); pictureBox1.Image = bitmap; }
Popularity: 13% [?]

February 13th, 2009
admin
Posted in
Tags:

