[Excerpt] matrix learning-how to use Matrix

Source: Internet
Author: User
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.

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.