SuperBerry
SuperBerry

Reputation: 1313

The text is too bold by DrawString on C#

I have use GDI DrawString method to draw text. When the program is running, the text on the screen seems very good, however once I saved the files to image, the font will be bolder than before. The normal will be bold, the bold will be much bolder. How to deal with this?

public override void DrawTo(Graphics g, int x, int y, int flag)
    {
        if (flag == 1)
        {
            Pen dpen = new Pen(Color.FromArgb(128, 0, 0, 0), 1);
            dpen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
            g.DrawRectangle(dpen, new Rectangle(Bounds.X + x, Bounds.Y + y, Bounds.Width, Bounds.Height));
        }

        if (!string.IsNullOrEmpty(Text))
        {

            g.DrawString(Text, Font, new SolidBrush(Color), new Rectangle(Bounds.X + x, Bounds.Y + y, Bounds.Width, Bounds.Height));
        }
    }

Upvotes: 4

Views: 3315

Answers (3)

Diego Quiros
Diego Quiros

Reputation: 59

Instead of setting TextRenderingHint to TextRenderingHint.AntiAlias, you should prefer to set it to TextRenderingHint.SingleBitPerPixelGridFit. For example:

g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;

Upvotes: 1

Ann
Ann

Reputation: 1

I had the same problem. I've tried to use TextRenderingHint, SmoothingMode, TextContrast but it changed nothing.

I've replaced graph.Clear(Color.Transparency) with graph.Clear(Color.White) and Text looks good now.

Upvotes: 0

SuperBerry
SuperBerry

Reputation: 1313

I got the solution.

g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

Just AntiAlias will solve that.

Upvotes: 6

Related Questions