2

I want to draw string in a Bitmap like this:

Font myfont=new Font("TimesNewRoman",18)
Bitmap bmpBitmap =new Bitmap(200,100);
Graphics g=Graphics.FromImage(bmpBitmap);
g.DrawString("SampleText",myfont,Brushes.Black);

How do I determine the size of bitmap?

andreister
  • 13,693
  • 2
  • 44
  • 45
mohammad
  • 1,248
  • 3
  • 15
  • 27

2 Answers2

3

Use the following function to measure the size of a string with respect to a certain Font.

SizeF Graphics.MeasureString(string text, Font font)

Also, ensure the TextRenderingHint for the Graphics is set to AntiAlias. This makes a world of difference when it comes to the readability of the text.


If you want to measure a string before you create your Bitmap, use the solution presented over here: https://stackoverflow.com/a/1003503/1828879

Community
  • 1
  • 1
Timothy Shields
  • 75,459
  • 18
  • 120
  • 173
0

Have you tried using bmpBitmap.Size to get both Height and Width, or bmpBitmap.Height and bmpBitmap.Width to get one or the other?

Xynariz
  • 1,232
  • 1
  • 11
  • 28