views:

57

answers:

2

I am generating a png image that contains a text dinamically written. I need to create the bitmap with the minimum width for file size reasons.

+3  A: 

Use Graphics.MeasureString() to compute the width.

Lucero
A: 

You can also use TextRenderer for slightly more accuracy. See this article for differences between this and Graphics.MeasureString :

http://msdn.microsoft.com/en-us/magazine/cc751527.aspx

James Westgate
It doesn't return exactly the same results as Graphics.MeasureString, so If the OP wants to know the size of the string actually drawn by the Graphics, Graphics.MeasureString is a better choice
Thomas Levesque
Agreed ........
James Westgate