Marlon
Marlon

Reputation: 1877

Graphics object not using correct font when drawing a string

I'm creating a console app that will generate a image with text in it. I'm using the following code:

Bitmap bmp = new Bitmap(400, 50);
Graphics g = Graphics.FromImage(bmp);
Font f = new Font("Arial", 12, FontStyle.Regular);
g.DrawString("My text", f, Brushes.Black, 10, 10);

But the result is always the following image, regardless of what font family i use instead of Arial.

enter image description here

Upvotes: 0

Views: 139

Answers (1)

Alexander Petrov
Alexander Petrov

Reputation: 14251

The newly created bitmap has a transparent background. Because of this, anti-aliasing, smoothing, and similar functions do not work when drawing text.

Fill the graphics with some color

g.Clear(Color.White);

Upvotes: 1

Related Questions