Android ApiDemos example (80): Graphics-& gt; Sweep

Source: Internet
Author: User

The color gradient direction of the SweepGradient is not a ring, but a fan-shaped sweep is taken as the center of a certain point.

The constructors of SweepGradient:

Public SweepGradient (float cx, float cy, int [] colors, float [] positions)
Public SweepGradient (float cx, float cy, int color0, int color1)

Cx, cy specify the center, color1, color0, or colors specify the gradient color. When more than two colors are used, you can also use positions to specify the relative position of each color, if positions is set to NULL, the color is evenly distributed.

The base classes of LineerGradient, RadialGradient, and SweepGradient classes are Shader (similar to the Brush class in GDI). Shader defines a Local Matrix corresponding to it and can perform Coordinate Transformation on Shader. In this example, the Shader's LocalMatrix is used to rotate different angles to form the animation effect:

[Java]
Float x = 160;
Float y = 100;
MShader = new SweepGradient (x, y, new int [] {Color. GREEN,
Color. RED,
Color. BLUE,
Color. GREEN}, null );
MPaint. setShader (mShader );

...
Protected void onDraw (Canvas canvas ){
...
MMatrix. setRotate (mRotate, x, y );
MShader. setLocalMatrix (mMatrix );
MRotate + = 3;
If (mRotate> = 360 ){
MRotate = 0;
}
Invalidate ();
...
}

Float x = 160;
Float y = 100;
MShader = new SweepGradient (x, y, new int [] {Color. GREEN,
Color. RED,
Color. BLUE,
Color. GREEN}, null );
MPaint. setShader (mShader );
 
...
Protected void onDraw (Canvas canvas ){
...
MMatrix. setRotate (mRotate, x, y );
MShader. setLocalMatrix (mMatrix );
MRotate + = 3;
If (mRotate> = 360 ){
MRotate = 0;
}
Invalidate ();
...
} In this example, you can press the "D", "T" key to display the usage of the Paint Dither (Dither definition can be found in the Android ApiDemos example resolution (59): Graphics-> ColorFilters) and the display effects of different "scanning speeds:

 
Author: mapdigit
 


 


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.