Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

ASP.NET with 2.0/3.5, Silverlight 2/3/4, WPF, WCF, nHibernet, Javascript, Jquery, Ajax, C#-2.0/3.0, Sql server 2005/2008, MySql 5.1., RIA WCF Service, Entity Framework.
Browse by Tags · View All
.Net 8
SQL 5
Sql Server 3
T SQL 3
linq 3
ORM 2
ORM 2
Browser 2
Silverlight 2
C# 2

Archive · View All
December 2011 9
January 2012 4
July 2012 3
October 2012 1
September 2012 1
August 2012 1
May 2012 1
April 2012 1
March 2012 1
February 2012 1

Convert Text in to Image using C#

Dec 23 2011 11:35AM by Viral Sarvaiya   

.Net provide us very good functionality to Create image from text, here is function that return Bitmap and take string as a parameter.

private Bitmap CreateBitmapImage(string TextImage)
{
    Bitmap objBmp = new Bitmap(1, 1);
    int Width = 0;
    int Height = 0;

    // Create the Font object for the image text drawing.    
    Font objFont = new Font("Arial", 20, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel);

    // Create a graphics object to measure the text's width and height.
    Graphics objGraphics = Graphics.FromImage(objBmp);   

    // This is where the bitmap size is determined.
    Width = (int)objGraphics.MeasureString(TextImage, objFont).Width;
    Height = (int)objGraphics.MeasureString(TextImage, objFont).Height;

    // Create the bmpImage again with the correct size for the text and font.
    objBmp = new Bitmap(objBmp, new Size(Width, Height));

    // Add the colors to the new bitmap.
    objGraphics = Graphics.FromImage(objBmp);

    // Set Background color
    objGraphics.Clear(Color.White);
    objGraphics.SmoothingMode = SmoothingMode.AntiAlias;
    objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
    objGraphics.DrawString(TextImage, objFont, new SolidBrush(Color.FromArgb(102, 102, 102)), 0, 0);
    objGraphics.Flush();
    return (objBmp);
}

From this We get direct Image of the text.

Enjoy...

Jay Ganesh.

Tags: Bitmap,Convert Text in to Image using C#,Convert Text to Image, Generate Image from Text, Image, Image to Text, Text, .Net


Viral Sarvaiya
176 · 1% · 279
4
 
0
Lifesaver
 
0
Refreshed
 
 
0
Incorrect



Submit

4  Comments  

  • Good one Viral..

    Recently i also has the same requirement of converting text to image. We almost ended with same code. It has 2 additional properties to improve quality.

        objGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
        objGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
    
    commented on Dec 26 2011 8:35AM
    Ramireddy
    2 · 40% · 12972
  • Thanks Ramireddy for appreciate. and help to improve knowledge.

    commented on Dec 26 2011 10:10AM
    Viral Sarvaiya
    176 · 1% · 279
  • hello how do this function convert bitmap to led do matrix(8*8) and display to picturebox and scroll it from up to down or left to right? Thanks. javidian. hosseinjavidian@gmail.com

    commented on Aug 10 2012 8:45AM
    hosseinzpp
    3015 · 0% · 2
  • I actually have a same problem and I need to import the font into the C# and convert it into pixels (bitmap).

    Could you please advice on that how it is possible to do as I am not very familiar with C# functions?

    Many thanks for your help

    commented on Jan 17 2014 11:03AM
    start.mo
    3015 · 0% · 2

Your Comment


Sign Up or Login to post a comment.

"Convert Text in to Image using C#" rated 5 out of 5 by 4 readers
Convert Text in to Image using C# , 5.0 out of 5 based on 4 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]