Http://www.moandroid.com /? P = 1781
In the previous article, we introduced matrix from the perspective of advanced mathematics. In this article, we will combine android in Android. graphics. for details about the Matrix, remember the image rotation matrix we mentioned earlier:
Which of the following is the simplest rotation of 90 degrees:
There is a corresponding rotation function in Android. Graphics. Matrix:
Matrix matrix = new matrix ();
Matrix. setrotate (90 );
Test. Log (maxtrix_tag, "setrotate (90): % s", matrix. tostring ());
View the value of the matrix after running (output through log ):
It is basically the same as the above formula (Android. Graphics. matrix uses floating-point numbers while we use integers ).
With the above example, you can try it yourself. Through the above example, we also found that we can also initialize the Matrix directly, for example, to rotate 30 degrees:
We have introduced so many topics.ImageThere are two types: horizontal image and vertical image. First, we will introduce how to implement a vertical mirror. What is a vertical mirror is not described in detail. The vertical image changes of the image can also be represented by matrix changes. Set the point P0 (x0, y0) to p (x, y), and the Image Height to fheight, the width is fwidth, and the coordinates of P0 (x0, y0) in the original image after the vertical image are changed to (x0, fheight-y0 );
X = x0
Y = fheight-y0
Export the corresponding matrix:
Final FloatF [] = {1.0f, 0.0f, 0.0f, 0.0f,-1.0f, 1200000f, 0.0f, 0.0f, 1.0f };
Matrix matrix =NewMatrix ();
Matrix. setvalues (f );
The result is as follows:
You can try horizontal images in a similar way.
In fact, you can use the following method to implement a vertical image:
Matrix matrix =NewMatrix ();
Matrix. setscale (1.0,-1.0 );
Matrix. posttraslate (0, fheight );
This is what we will describe in detail later.