C# 使用 GraphicsPath 在图像上倾斜文本

本文关键字:倾斜 文本 图像 使用 GraphicsPath | 更新日期: 2023-09-27 18:31:51

我目前正在使用以下代码向图像添加文本:

using (GraphicsPath graphicsPath = new GraphicsPath())
{
    graphicsPath.AddString(
        "sample text",
        new FontFamily("Times New Roman"),
        (int)FontStyle.Bold,
        graphics.DpiY * 12 / 72,
        new PointF(0,0),
        StringFormat.GenericDefault
    );
    graphics.FillPath(new SolidBrush(Color.Red), graphicsPath);
}

我这样做是为了以后有一条添加文本边框的路径。

我希望能够为特定的 X/Y 值倾斜文本,但无法弄清楚如何做到这一点。 对GDI来说有点新。

任何帮助将不胜感激。

C# 使用 GraphicsPath 在图像上倾斜文本

使用链接,我想出了答案:

https://msdn.microsoft.com/en-us/library/a4t01h2x%28v=vs.110%29.aspx

using (GraphicsPath graphicsPath = new GraphicsPath())
{
    graphicsPath.AddString(
        "sample text",
        new FontFamily("Times New Roman"),
        (int)FontStyle.Bold,
        graphics.DpiY * 12 / 72,
        new PointF(0,0),
        StringFormat.GenericDefault
    );
    Matrix matrix = new Matrix();
    matrix.Shear(10, 0);
    graphics.MultiplyTransform(matrix);
    graphics.FillPath(new SolidBrush(Color.Red), graphicsPath);
}