Search code examples
c#system.drawing

How to remove extra spacing between words in writing text by GraphicPath c#


Code:

Bitmap btm = new Bitmap(800, 400);
Graphics g = Graphics.FromImage(btm);
using (GraphicsPath gp = new GraphicsPath())
using (Pen outline = new Pen(Brushes.Green, 2)
{ LineJoin = LineJoin.Round })
using (StringFormat sf = new StringFormat())
using (Brush foreBrush = new SolidBrush(System.Drawing.Color.White))
{
    gp.AddString("سلام", new FontFamily("Lalezar"), (int)FontStyle.Regular,
        26, new PointF(0, 0), sf);
    g.ScaleTransform(8f, 8f);
    g.SmoothingMode = SmoothingMode.AntiAlias;
    g.InterpolationMode = InterpolationMode.Bilinear;
    g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
    g.CompositingQuality = CompositingQuality.HighQuality;
    g.DrawPath(outline, gp);
    g.FillPath(foreBrush, gp);
}

Output: output.png

I have this problem with all fonts.

I don't know what to do, thank you for your help.


Solution

  • Hi there im so happy :D cause I found my result!

    i used new GraphicsPath(FillMode.Winding) and it works :D