Ответ 1
Да. Вместо DrawString используйте следующую последовательность вызовов:
-
new GraphicsPath
(создает пустойGraphicsPath
) -
GraphicsPath.AddString
(объектGraphicsPath
теперь представляет собой контур текста) -
Graphics.DrawPath
(рисует контур в любомPen
, который вам нужен)
Если вам нужно использовать GraphicsPath.AddString
рядом с Graphics.DrawString
, вам нужно преобразовать размеры шрифта, потому что Graphics.DrawString
ожидает "размер точки", а GraphicsPath.AddString
ожидает "em size". Формула преобразования просто emSize = g.DpiY * pointSize / 72
.
Вот пример кода:
// assuming g is the Graphics object on which you want to draw the text
GraphicsPath p = new GraphicsPath();
p.AddString(
"My Text String", // text to draw
FontFamily.GenericSansSerif, // or any other font family
(int) FontStyle.Regular, // font style (bold, italic, etc.)
g.DpiY * fontSize / 72, // em size
new Point(0, 0), // location where to draw text
new StringFormat()); // set options here (e.g. center alignment)
g.DrawPath(Pens.Black, p);
// + g.FillPath if you want it filled as well