C# skew text on image using GraphicsPath

886 Views Asked by At

I'm currently adding text to an image using the following code:

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

I'm doing it this way so that I have a path to follow for adding text borders later.

I want to be able to skew the text for a specific X/Y value but cannot figure out how to do it. Bit new to GDI.

Any help would be greatly appreciated.

1

There are 1 best solutions below

0
On BEST ANSWER

Using the link, I figured out the answer:

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