Http://www.moandroid.com /? P = 1771
Previously, I learned about matrices in linear algebra and had some knowledge about the basic operations of matrices. I learned how to use matrices to change images when I used GDI + some time ago, after reading this article, I will summarize it here.
First, let's take a look at the 3x3 matrix, which is divided into four parts. The reason for splitting the data into four parts is described in detail later.
First, we will give you a simple example: after we have set the point P0 (x0, y0) for translation, we will move it to p (x, y), where the translation in the X direction is △x, if the translation in the Y direction is △y, then the coordinates of P (x, y) are:
X = x0 + △x
Y = y0 + △y
The matrix expression is as follows:
The above is similar to the image translation. Through the above matrix, we find that you only need to modify the two elements in the upper right corner of the matrix.
Let's look back at the division of the above matrix:
In order to verify the functional division above, we will give a specific example: now we have set the point P0 (x0, y0) to pan and move it to p (x, y), where X is multiplied by, Y to B,
The matrix is: Verify according to the method similar to the previous "Translation.
The image rotation is slightly complicated: the number of pairs after the θ angle is rotated by P0 (x0, y0) is p (x, y ). By using vectors, we can get the following:
X0 = r cos α
Y0 = r sin α
X = r cos (α-θ) = x0 cos θ + y0 sin θ
Y = r SIA (α-θ) =-x0 sin θ + y0 cos θ
So we get the matrix:
What if the image rotates around a certain point (a, B? First, you need to translate the coordinates to the point, then rotate, and then translate the rotated image back to the original coordinate origin. We will introduce it in detail in the subsequent sections.