Android ColorMatrix

Coordinate matrix

It is introduced in advanced mathematics. In image processing, it is mainly used for plane scaling, translation, rotation and other operations.

In Android, the matrix is composed of 9 float values, which is a 3 * 3 matrix. Better remember. As shown below

Meaning of each field:

SiNx and cosx above represent the COS and sin values of the rotation angle. Note that the rotation angle is calculated in a clockwise direction.

Translatex and translatey represent the amount of translation of X and y. Scale is the scale, 1 is constant, and 2 is 1 / 2 of the scale.

How to use

Set, pre, post methods

When matrix calls a series of set and post methods, it can be regarded as inserting these methods into a queue Of course, the execution is called from beginning to end in the queue among

Pre means to insert a method at the head of the team,

Post means to insert a method at the end of the queue

Set means to empty the current queue and always be in the middle of the queue

After a set is executed: the pre method is always inserted into the front of the queue at the front of the set, and the post method is always inserted into the back of the queue at the back of the set

Example 1:

Only m.settranslate (80,80) is valid because m.setrotate (45); Is cleared

Example 2:

Execute m.settranslate (80,80) first; After that, execute m.postrotate (45);

Example 3:

Execute m.settranslate (80,80) first; Execute M. prerotate (45) after;

Example 4:

Execution order: 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 finds the front end of the queue

Example 5:

Execution sequence: m.pretranslate (0.5f, 0.5f) - > m.setscale (0.8f, 0.8f) - > m.postscale (3F, 3f) Note: m.setscale (0.8f, 0.8f) clears the previous m.posttranslate (20,20) and m.prescale (0.2f, 0.5f);

Examples of other specific methods:

1. Settranslate (float DS, float dy): controls the matrix to translate. 2. Setskew (float KX, float KY, float Px, float py): controls the matrix to tilt around PX and py. KX and KY are the tilt distances in the X and Y directions. 3. Setskew (float KX, float KY): controls the tilt of the matrix. KX and KY are the tilt distances in the X and Y directions. 4. Setrotate (float degrees): controls the rotation of the matrix, and degrees controls the rotation angle. 5. Setrotate (float degrees, float py): set PX and py as axes for rotation, and degrees controls the rotation angle. 6. Setscale (float SX, float SY): set the matrix to scale. SX and sy control the scaling in the X and Y directions. 7. Setscale (float SX, float sy, float py): set the matrix to scale with PX and py as axes, and SX and sy control the scaling in X and Y directions.

Write at the end:

Here, the processing of moving and rotating pictures can be realized not only through the matrix class, but also through animation animation

The differences between them are:

1. When using the matrix class, the movement and rotation of the picture can only be on the control. The control itself does not move, and the content in the control moves. In practice, you need to consider the size of the control itself, because the excess part will not be displayed.

2. When using animation animation, the control itself moves.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>