Search code examples
c#.netgdi+matrixsystem.drawing

System.Drawing.Matrix, I understand what it does, but how does it work?


I've used the Matrix class a thousand times. I have an elementary grasp of matrix mathematics, it's been years since I've had a class on the subject. But I don't fully understand what this class is doing under the hood to manipulate the points in a GraphicsPath.

What, specifically, is it doing in there as it pertains to GraphicsPaths in particular? Or another way to look at it, if the Matrix class didn't exist, and I had to create my own, what would it look like and what would it do? (I'm not creating my own I just want to understand it)

Furthermore, does anyone know the dimensions of the matrix used in the Matrix class?

EDIT: I've narrowed it down to the following call in reflector. From there, I've got bub kiss.

[DllImport("gdiplus.dll", CharSet=CharSet.Unicode, SetLastError=true, ExactSpelling=true)]
internal static extern int GdipTransformPath(HandleRef path, HandleRef matrix);

Solution

  • In this case, the Matrix class is a 2D transformation matrix. The Matrix is used to scale, rotate and / or translate the graphics path. The math is relatively straight forward. You can look at it here: http://en.wikipedia.org/wiki/Transformation_matrix