Text in Bitmap question:

  • Thread starter Thread starter Ivan Demkovitch
  • Start date Start date
I

Ivan Demkovitch

Hi!

I'm outputing text to bitmap using following code:

//Create new bitmap
oPic = new Bitmap(100,150);

//Get Graphics
Graphics g = Graphics.FromImage(oPic);

//Set quality to high.
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;

g.Clear(Color.White);

Font myFont = new Font("Arial", 7);
SolidBrush myBrush = new SolidBrush(Color.Black);

// Create point for upper-left corner of drawing.
float x = 0.0F;
float y = 0.0F;

// Set format of string.
StringFormat myFormat = new StringFormat();
myFormat.FormatFlags = StringFormatFlags.FitBlackBox;

// Create rectangle for drawing.
float width = 99.0F;
float height = 149.0F;
RectangleF myRect = new RectangleF( x, y, width, height);
// Draw rectangle to screen.
Pen whPen = new Pen(Color.Black);
g.DrawRectangle(whPen, x, y, width, height);

g.DrawString(s, myFont, myBrush, myRect, myFormat);


But I have following problem:

Sometimes I have more text then could fit in rectangle specified.

Ideally I would like to create bitmap with width(100) and heigth that allow
for all text to be fit.

Any ideas on how to do this?

Thanks!
 
Hi Ivan,

You might want to use the Graphics.MeasureString method. It will give you
size information which might help you.

Eric-Paul Jansen
Inforay International B.V. (http://www.inforay.com)
The Netherlands
 
Back
Top