【问题标题】:C# Caption imageC# 标题图片
【发布时间】:2013-05-27 01:22:27
【问题描述】:

我正在为图像添加字幕,但是对于 M 和 W 等字母来说,边角太尖了。

有圆角的方法吗? 这是我目前的方法。它有很长的引用,因为我在 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;
}

【问题讨论】:

    标签: c# .net image graphic


    【解决方案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);
    }
    

    【讨论】:

    • 哦,是的,这只是第一次。
    猜你喜欢
    • 2019-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-29
    • 2012-10-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多