2013-05-31 50 views
4

我字幕的圖像,但邊角信件如M和WC#字幕圖像

太尖銳

enter image description here

是否有圓角的方法是什麼? 這是我目前的方法。由於我在WPF中使用它,所以它有很長的引用,我不希望它發生衝突。

public static System.Drawing.Image captionImage(System.Drawing.Image img, string text, string font, float fontSize, int left, int top) 
{ 
    System.Drawing.FontFamily c; 

    c = System.Drawing.FontFamily.Families.Where(x => x.Name.ToLower() == font.ToLower()).First(); 

    if (c != null) 
    { 
     using (System.Drawing.StringFormat sf = new System.Drawing.StringFormat()) 
     { 
      sf.Alignment = System.Drawing.StringAlignment.Near; 
      sf.LineAlignment = System.Drawing.StringAlignment.Near; 

      using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(img)) 
      { 
       using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath()) 
       { 
        path.AddString(text, c, 0, fontSize, new System.Drawing.Point(left, top), sf); 

        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; 
        g.DrawPath(new System.Drawing.Pen(System.Drawing.Color.Black, fontSize * 0.3f), path); 
        g.FillPath(System.Drawing.Brushes.White, path); 
       } 
      } 
     } 
    } 

    return img; 
} 

回答

1

我想通了。

我不得不創建一個筆對象並將其線條設置爲圓。

using (System.Drawing.Pen p = new System.Drawing.Pen(System.Drawing.Color.Black, fontSize * 0.3f)) 
{ 
    p.LineJoin = System.Drawing.Drawing2D.LineJoin.Round; 
    g.DrawPath(p, path); 
    g.FillPath(System.Drawing.Brushes.White, path); 
} 
+0

如果這確實解決了您的問題,您可以將此答案標記爲已接受的答案。 –

+1

@FurkanEkinci它說我不能接受它2天 – John

+0

哦,是的,這是隻有第一次。 –