Android Matrix Colormatrix_android

Source: Internet
Author: User

Chinese name: Coordinate matrix

Advanced mathematics has introduced, in the image processing aspect, is mainly uses in the plane the scale, the translation, the rotation and so on the operation.

In Android, the Matrix is made up of 9 float values and is a 3*3. It's best to remember. The following figure

Meaning of each field:

The Sinx and cosx above indicate the Cos value and the sin value of the rotation angle, and Note that the rotation angle is calculated in the clockwise direction.

Translatex and Translatey represent The amount of translation for x and Y. scale is the scaling ratio,1 is invariant,2 is the zoom 1/2, this way.

How to use

Set,pre,post method

When the matrix calls a series of set,pre,post methods, it can be considered to insert these methods into a queue. Of course, the execution is invoked in the order of the queues.
which

The pre indicates that a method is inserted into the team head,

Post indicates that a method is inserted at the end of the team.

The set representation empties the current queue and is always in the middle of the queue.

When a set is executed: The Pre method is always inserted at the front of the queue at the front of the set, and the Post method is always inserted at the end of the queue at the back of the set

Example one:

Matrix M = new Matrix ();
M.setrotate (); 
M.settranslate (80, 80);

Only M.settranslate (80, 80) is valid because M.setrotate (45);

Example two:

Matrix M = new Matrix ();
M.settranslate (a);
M.postrotate (45);

Execute M.settranslate (80, 80) First, then execute M.postrotate (45);

Example three:

Matrix M = new Matrix ();
M.settranslate (a);
M.prerotate (45);

Execute M.settranslate (80, 80) First, then execute M.prerotate (45);

Example four:

Matrix M = new Matrix ();
M.prescale (2f,2f);  
M.pretranslate (50f, 20f);  
M.postscale (0.2f, 0.5f);  
M.posttranslate (20f, 20f); 

Order of execution: M.pretranslate (50f, 20f)-->m.prescale (2f,2f)-->m.postscale (0.2f, 0.5f)-->m.posttranslate (20f, 20f)
Note: m.pretranslate (50f, 20f) executes before M.prescale (2F,2F), because it checks the front end of the queue.

Example five:

Matrix M = new Matrix ();
M.posttranslate (a);  
M.prescale (0.2f, 0.5f);
M.setscale (0.8f, 0.8f);  
M.postscale (3f, 3f);
M.pretranslate (0.5f, 0.5f);

Order of execution: M.pretranslate (0.5f, 0.5f)-->m.setscale (0.8f, 0.8f)-->m.postscale (3f, 3f)
Note: The M.setscale (0.8f, 0.8f) clears the front m.posttranslate (20, 20) and M.prescale (0.2f, 0.5f);

Other examples of specific methods are:

1, settranslate (float ds,float dy): Control matrix for translation.
2, Setskew (float kx,float ky,float px,float py): Control matrix to px, py as the axis tilt. KX, KY in the X, y direction of the tilt distance.
3, Setskew (float kx,float ky): Control matrix to tilt. KX, KY in the X, y direction of the tilt distance.
4, Setrotate (float degrees): control matrix for rotation, degrees control rotation angle.
5, Setrotate (float degrees,float px,float py): Set to PX, py as the axis of rotation, degrees control the angle of rotation.
6, Setscale (float sx,float sy): Set the matrix for scaling, SX, SY control x, y in the direction of the scaling ratio.
7, Setscale (float sx,float sy,float px,float py): Set the Matrix to PX, py for the axis of scaling, SX, SY control x, y direction of the scaling ratio.

Written at the end:

Here to the picture to move, rotation and so on processing, in addition to through the Matrix class, but also through the animation animation to achieve

The difference between them is:

1. When using the matrix class, pictures can be moved and rotated only on the control. The inside of the control itself does not move, the contents of the control move. The size of the control itself needs to be considered when it is actually done, because the excess portion is not displayed.

2. When using the animation animation, the control itself is moved.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.