How to implement and summarize Android image effects

Android graphics effects

Recently, in the company's project, there is a need to do picture special effects. I wrote my own code to realize special effects, but it is not very good. I searched the Internet for relevant materials and sorted out more comprehensive materials of Android picture special effects. You can have a look,

1、 Graphic effects (I) implementation of special effects

In Android, there are three ways to implement special effects, setXXX method, postxxx and prexxx () method.

1. SetXXX () method is used to directly set the value of the matrix. Every time setXXX () method is used, the whole matrix will change.

2. The postxxx method is used to set the value for the matrix in the way of post multiplication. You can use post several times continuously to complete multiple transformations

3. The prexxx method is used to set the value for the matrix in the way of pre multiplication. The setting operation using the prexxx method occurs first

(2) Manifestation of special effects

1. Rotation: setrotate (float dgrees, float Px, float py)

PX and py are the axes of rotation

2. Zoom: setscale (float SX. Float SY)

SX and sy are used to specify the scaling ratio of x-axis and y-axis. Android provides seetscale(), postscale() and prescale() methods of android.graphics.matrix class to scale the image. These three methods have the same syntax format except for different method names

3. Tilt setskew (float KX. Float KY)

KY and KY are used to specify the tilt amount of x-axis and y-axis. Android provides setskew(), postskew() and presskew() methods of android.graphics.matrix class to tilt the image. These three methods have the same syntax format except for different method names. Setskew (float SX, float sy, float py) PX and py tilt with them as the axis

4. Translate settranslate (float DX. Float dy)

Dy and Dy are used to specify the X and Y coordinates of the moved position. Android provides settranslate(), posttranslate() and pretranslate() methods of android.graphics.matrix class to translate the image. These three methods have the same syntax except for different method names

2、 Bitmapshader rendered image

In Android, bitmapshader class is mainly used to render images. If you need to cut an image into ellipses or circles and display it on the screen, you can use bitmapshader class. The basic steps of using bitmapshader class to render images are as follows

Create an object of bitmapshader class and set the render object through the setshader() method of paint. When painting an image, use the brush with the setshader() method set

3、 The following is an example of graphic effects control

The program controls the zoom in, zoom out, rotation and tilt of the image by pressing the key.

(1) Custom view code

(2) Call class

The program controls the enlarged effect through the W key:

The program controls the effect after tilting through the D key:

Thank you for reading, hope to help you, thank you for your support to this site!

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