在 GraphicsPath 中添加字符串时,我需要更改字符之间的距离。做这个的最好方式是什么?
问问题
880 次
1 回答
0
您可以单独绘制每个字符并调整字符之间的距离,例如。
public void DrawText(string text, Point at, float distanceBetweenChars, FontFamily fontFamily, float fontSize, Graphics graphics)
{
float currentX = at.X;
for (int i = 0; i < text.Length; i++)
{
using (var path = new GraphicsPath())
{
path.AddString(text.Substring(i, 1), fontFamily, (int)FontStyle.Regular, fontSize,
new Point((int)currentX, at.Y),
StringFormat.GenericDefault);
RectangleF bounds = path.GetBounds();
currentX += bounds.Width + distanceBetweenChars;
graphics.FillPath(new SolidBrush(Color.Black), path);
}
}
}
}
于 2012-08-22T13:41:34.077 回答