C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Graphics »

Create image from the text


Posted Date: 11 Feb 2009    Resource Type: Code Snippets    Category: Graphics
Author: vipulMember Level: Diamond    
Rating: 1 out of 5Points: 12



Hello.every one
my last post is for how to add text on the image (water mark text). Now i am describing how to create image from the given text. in that you have to only give your text and image will be created and display on the page or you can save it.

Function
--------


private void createImage()
{
string myString = "This is a string.My highlight word : search highlighted word."; // give your string

Bitmap b = new Bitmap(myString.Length * 10, 40);
Graphics g = Graphics.FromImage((System.Drawing.Image)b);

CharacterRange[] CharRanges = new CharacterRange[] { new CharacterRange(0, myString.Length) };
StringFormat stringFormat = new StringFormat();
stringFormat.SetMeasurableCharacterRanges(CharRanges);
Font MyFont = new Font(FontFamily.GenericSansSerif, 20.0F, GraphicsUnit.Pixel);

Rectangle MyRectangle = new Rectangle(10, 10, myString.Length * 10, 30);
RectangleF MyRectangleF = (RectangleF)MyRectangle;

Region[] charRegion = g.MeasureCharacterRanges(myString, MyFont, MyRectangleF, stringFormat);
g.DrawString(myString, MyFont, Brushes.Red, MyRectangleF);

//g.FillRegion(new SolidBrush(Color.FromArgb(50, Color.Black)), charRegion[0]);

//b.Save(Server.MapPath("MyImage.png"), System.Drawing.Imaging.ImageFormat.Png);
MemoryStream m = new MemoryStream();
b.Save(m, System.Drawing.Imaging.ImageFormat.Png);
m.WriteTo(Response.OutputStream);
b.Dispose();
MyFont.Dispose();
g.Dispose();
}



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Image creation from the text  .  Create image from the text  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Watermark on image : Draw string on the image
Previous Resource: Simple Visualization Type Application.
Return to Discussion Resource Index
Post New Resource
Category: Graphics


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use