GDI+ DrawString字间距处理

 

处理方案是将字符串转成字符,逐个绘制。

///   <summary>
///   绘制任意间距文字
/// </summary>
///   <param   name= "text "> 文本 </param>
///   <param   name= "g "> 绘图对象 </param>
///   <param   name= "startPoint "> 起始位置 </param>
///   <param   name= "font "> 字体 </param>
///   <param   name= "brush "> 画刷 </param>
///   <param   name= "sepDist "> 间距 </param>
private   void   DrawStringEx(string   text,   Graphics   g,   PointF   startPoint,   Font   font,   Brush   brush,   float   sepDist)
{
        PointF   pf   =   startPoint;
        SizeF   charSize;
        char[]   ch   =   text.ToCharArray();
 
        foreach   (char   c   in   ch)
        {
                charSize   =   g.MeasureString(c.ToString(),   font);
                g.DrawString(c.ToString(),   font,   brush,   pf);
                pf.X   +=   (charSize.Width   +   sepDist);
        }
}

 

更多:

使用GDI+ 处理图片成圆图

C#生成验证码实例

无法从带有索引像素格式的图像创建graphics对象(转)

posted @ 2020-01-30 12:50  天马3798  阅读(1411)  评论(0编辑  收藏  举报