编程语言
首页 > 编程语言> > C#使用GraphicsPath倾斜图像上的文本

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

作者:互联网

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

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有点陌生.

任何帮助将不胜感激.

解决方法:

通过链接,我找到了答案:

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

标签:graphicspath,gdi-2,skew,c
来源: https://codeday.me/bug/20191119/2033730.html