Implementation method of image rotation function developed by Android [based on matrix]

This paper describes the implementation method of image rotation function developed by Android. Share with you for your reference, as follows:

For image rotation in Android, you need to use matrix, which contains a 3 * 3 matrix, which is specially used for image transformation and matching. Matrix, called matrix in Chinese, is introduced in advanced mathematics. In image processing, it is mainly used for plane scaling, translation, rotation and other operations. The matrix has no mechanism. It must be initialized and implemented through the reset method and set method.

First, let's introduce matrix operation. Needless to say, addition and subtraction are too simple. Just add the corresponding bits. Image processing mainly uses multiplication. Here is a multiplication formula:

In Android, the matrix is composed of 9 float values, which is a 3 * 3 matrix. See the figure below.

It's ugly without professional tools. Explain that 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.

Matrix operations are divided into four types: translate, rotate, scale and skew. Each transformation provides three operation modes: set, post and pre in the Android API. In addition to translate, the other three operations can specify the center point. Set is to directly set the value of the matrix. Each time you set it, the entire matrix array will change.

Now we set the rotation angle through setrotate, create a bitmap object after rotation and other processing with createbitmap, and then draw the bitmap on the screen, so the rotation operation is realized.

The following uses an example to illustrate the use of matix and the way of rotation and operation effect.

The specific image rotation processing codes are as follows:

Finally, we can realize the optional image through the left and right keys of the keyboard. Here, we can realize the right rotation of the image:

More readers interested in Android related content can view the special topics of this site: summary of Android graphics and image processing skills, introduction and advanced tutorial of Android development, summary of Android debugging skills and common problem solving methods, summary of Android basic component usage, summary of Android view skills, summary of Android layout skills, and Android control usage summary

I hope this article will help you in Android programming.

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
分享
二维码
< <上一篇
下一篇>>