Properly draw text using Graphics Path

前端 未结 2 1174
一整个雨季
一整个雨季 2020-11-27 22:37

As you can see in the image below, the text on the picturebox is different from the one in the textbox. It is working alright if I use Graphics.DrawString() but

2条回答
  •  旧时难觅i
    2020-11-27 23:01

    Seems you are providing wrong measure for font size in the first place and then adding extra thickness to the brush. Try this instead:

    using (GraphicsPath path = new GraphicsPath())
    {
        path.AddString(
            text,                         
            _fontStyle.FontFamily,      
            (int)_fontStyle.Style,      
            e.Graphics.DpiY * fontSize / 72f,       // em size
            new Point(0, 0),                       // location where to draw text
            string_format);          
    
        e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
        e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
        e.Graphics.CompositingMode = CompositingMode.SourceOver;
        e.Graphics.DrawPath(new Pen(Color.Red), path);
    }
    

提交回复
热议问题