加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C#标题图片

发布时间:2020-12-15 21:51:44 所属栏目:百科 来源:网络整理
导读:我正在为一个图像添加字幕,但是对于像M和W这样的字母来说角落太尖锐了. 有圆角的方法吗? 这是我目前的方法.由于我在WPF中使用它,因此它有很长的引用,我不希望它发生冲突. public static System.Drawing.Image captionImage(System.Drawing.Image img,string
我正在为一个图像添加字幕,但是对于像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,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;
}

解决方法

毕竟我想通了.

我必须创建一个笔对象并将其线设置为圆形.

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);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读