String to Image Format format?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi I am attaching here a snapshot in which i am converting string to image <br/>
but the output is not correct as required?
<pre class="prettyprint string calendar="rn Febuary2012rn__________________________________________rn Sun Mon Tue Wed Thu Fri Satrnrn 1 2 3 4 rn 5 6 7 8 9 10 11 rn 12 13 14 15 16 17 18 rn 19 20 21 22 23 24 25 rn 26 27 28 29 rn";[/code]
<br/>

<img alt="" src="http://social.msdn.microsoft.com/Forums/getfile/199057



<pre class="prettyprint" style=" public static Image DrawText(String text, Font font, Color textColor, Color backColor)
{
//first, create a dummy bitmap just to get a graphics object
Image img = new Bitmap(1, 1);
Graphics drawing = Graphics.FromImage(img);

//measure the string to see how big the image needs to be
SizeF textSize = drawing.MeasureString(text, font);

//free up the dummy image and old graphics object
img.Dispose();
drawing.Dispose();

//create a new image of the right size
img = new Bitmap((int)textSize.Width, (int)textSize.Height);

drawing = Graphics.FromImage(img);

//paint the background
drawing.Clear(backColor);

//create a brush for the text
Brush textBrush = new SolidBrush(textColor);

drawing.DrawString(text, font, textBrush, 0, 0);

drawing.Save();

textBrush.Dispose();
drawing.Dispose();

return img;

}[/code]
Can you please help me whats wrong in above code<br/>
i call like this
GUIHelpers.DrawText(calendar,new Font("Times New Roman", 24),Color.Blue,Color.White);
Thanks
<br/>

View the full article
 
Back
Top