In Android, the processing of images requires the use of the Matrix class, which is a 3 x 3 matrix, and his processing of pictures is divided into four basic types:
1. Translate ———— Translation Transformation
2. Scale ———— Zoom transform
3, Rotate ———— rotation transformation
4, Skew ———— wrong-cut transformation
In the Android API, there are three modes of operation for each transformation: set (for setting values in matrix), post (post-multiply, according to the principle of the matrix, equal to the left), pre (multiply first, equal to right multiplication in the matrix). By default, these four transformations are all around the (0,0) point transformation, and of course can be customized around the center point, usually around the center point.
First of all, in the process of image processing, the most commonly used is to translate the picture, the method is Settranslate (), translation means to simply move the image on the x-axis and y-axis. The Settranslate method takes two floating-point numbers as parameters, representing the number of moves on each axis. The first parameter is the number that the image will move on the x-axis, and the second parameter is the number of images that will move on the y-axis. Panning with a positive number on the x-axis moves the image to the right, while using a negative number moves the image to the left. Panning with a positive number on the y-axis moves the image downward, while using a negative number moves the image up.
Looking at scaling, another useful method in the matrix class is the Setscale method. It takes two floating-point numbers as parameters, each representing the amount of scaling that is generated on each axis. The first parameter is the scale of the x-axis, and the second parameter is the scale of the y-axis. such as: Matrix.setscale (1.5f,1);
The more complex is the rotation of the picture, one of the built-in methods is the Setrotate method. It takes a floating-point number to represent the angle of rotation. Around the default point (0,0), positive numbers rotate the image clockwise, and negative numbers rotate the image counterclockwise, where the default point is the upper-left corner of the image, such as:
Matrix matrix = new Matrix (); matrix.setrotate (15);
Alternatively, you can call the Setrotate method using the rotation angle and the rotation point around it as a parameter. Select the center point of the image as the rotation point, such as:
Matrix.setrotate (15,bmp.getwidth ()/2,bmp.getheight ()/2);
For the wrong-cut transformation, which is mathematically called shear mapping (can be translated as "shear transformation") or transvection (contraction), it is a relatively special linear transformation. The effect of a split-cut transformation is to keep the x-coordinate (or y-coordinate) of all points intact, while the corresponding y-coordinate (or x-coordinate) shifts proportionally, and the size of the translation is proportional to the vertical distance of the point to the x-axis (or y-axis). The split-cut transformation, which belongs to the equal area transformation, is the area of a shape before and after the wrong-cut transformation.
A particularly useful method for programs is Setscale and Posttranslate, which allow you to flip an image across a single axis (or two axes). If scaled with a negative number, the image is drawn to the negative space of the coordinate system. Because the (0,0) point is in the upper-left corner, using a negative number on the x-axis causes the image to be drawn to the left. So we need to use the Posttranslate method to move the image to the right, such as:
Matrix.setscale ( -1, 1); Matrix.posttranslate (Bmp.getwidth (), 0);
You can do the same thing on the Y axis, flipping the image so that it is inverted. The same effect can be achieved by rotating the image 180 ° around the center point on the two axes, such as
Matrix.setscale (1,-1); Matrix.posttranslate (0, Bmp.getheight ());
Use of the matrix image processing class for Android development