Reputation: 1313
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
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
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
Reputation: 1313
I got the solution.
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
Just AntiAlias will solve that.
Upvotes: 6