Question

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);
Was it helpful?

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

OTHER TIPS

One important thing to note if you are creating your own matrix class that is converting back and forth to the System.Drawing.Matrix class, is that the .NET one does not use the most commonly used standard when transforming points.

The .NET Matrix seems to be transposed before the transformation is taking place.

Also read the background here: http://www.codeproject.com/KB/recipes/psdotnetmatrix.aspx

A GraphicsPath is, basically, a collection of points and a flags that explain how the points relate to one another. The matrix class simply applies the matrix to those points.

You could implement the same thing: 1. Create a new, empty GraphicsPath 2. Using a GraphicsPathIterator, iterate the paths (and subpaths) 3. Take each point and apply the matrix 4. Add that point to the new, GraphicsPath

But don't do it. The types in GraphicsPath are not well documented.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top