4

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));
        }
    }
Steve Lillis
  • 3,263
  • 5
  • 22
  • 41
SuperBerry
  • 1,193
  • 1
  • 12
  • 28
  • Call `g.Clear(...);` ? Post more code so we have a chance of helping you. – LarsTech Jul 15 '14 at 01:56
  • May be you need to mention the fonts properly (which should be available for both screen and printer) – AjayR Jul 15 '14 at 02:05
  • Which font(s) are you actually using? How are you treating the DPI? – TaW Jul 15 '14 at 07:50
  • I used "Tahoma" font, but no matter what font I use, the text on the saved image will be stronger than normal. I didn't set DPI. You can see here is the DrawString result before saving: [link](http://www.hihisoft.com/1.png), and this is the saved image: [link](http://www.hihisoft.com/2.png) – SuperBerry Jul 15 '14 at 10:47
  • 1
    We still need to see your relevant code that reproduces the problem. – LarsTech Jul 15 '14 at 16:32
  • Added the code. But the problem is the rendering while saving the file I think. – SuperBerry Jul 16 '14 at 05:18

3 Answers3

6

I got the solution.

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

Just AntiAlias will solve that.

SuperBerry
  • 1,193
  • 1
  • 12
  • 28
1

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;
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
0

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.

Ann
  • 1