The documentation for this gives a couple of examples but I can't find anything that walks through what each setting in the transform does.
I'm trying come up with a transform that will do a vertical flip of what is drawn.
thanks - dave
The transform is stored in a 3x3 matrix, and it's hard to tell intuitively what each of the components of the matrix does. That's why you're given a set of functions to work with, that you can chain together. For example, if you want to to rotate an image by 90 degrees clockwise, and then make it twice as large, you can use
Matrix myMatrix = new Matrix();
myMatrix.Rotate(90);
myMatrix.Scale(2, 2, MatrixOrder.Append);
The MatrixOrder.Append
indicates that the scaling must be done after the previous transformations (the order is important here).
The main functions you want to use are :
RotateAt(Single a, Point o)
rotates the image clockwise around a pointScale(Single a, Single b)
scales the image in the X and Y axes - basically, (x, y) becomes (ax, by)Translate(Single a, Single b)
translates the image on the X and Y axes - basically, (x, y) becomes (a + x, b + y).To flip an image vertically, you simply need a Scale(-1, 1)
. Each point (x, y) will be transformed into (-x, y). If you need to flip the image around a different vertical axis than the axis y = 0, then you need to combine it with Translate
.
Note that mathematically speaking, any affine transform can be decomposed into the product of translation, rotation and scaling matrices. The API you're using also provides a few more convenience functions such as Shear
if you don't want to go through the calculations.
Here is a more detailed explanation. It includes some code at the end.