The shader class provided by Android is primarily rendered images and some geometry.
Shader has several direct subclasses:
Bitmapshader: Mainly used to render images
LinearGradient: Used for linear rendering
Radialgradient: Used for ring rendering
Sweepgradient: Scan Gradient---Scan gradients around a central point like the radar scan in a movie, for gradient rendering.
Composeshader: Combined rendering, which can be combined with several other subclasses.
1 Bitmapshader
The renderer shades a bitmap as a texture. Bitmaps can be duplicated or set mode.
Public Bitmapshader(Bitmap bitmap,shader.tilemode tilex,shader.tilemode Tiley)
Call this method to produce a renderer (Shader) that draws a bitmap.
Bitmap bitmaps used within the renderer
Tilex the tiling mode for x to draw the bitmap in. X-Directional tile pattern on the bitmap
Tiley the tiling mode for Y-draw the bitmap in. Y-Direction tile pattern on the bitmap
Tilemode: (a total of three kinds)
CLAMP: If the renderer exceeds the original boundary range, the range edge staining is copied.
REPEAT: Landscape and portrait Repeat renderer picture, tiled.
MIRROR: Horizontal and vertical duplicate renderer picture, this is not the same as the repeat repetition, he is tiled in a mirrored manner.
2 lineargradient
[Java]View PlainCopy
- Public lineargradient (float x0, float y0, float x1, float y1, int[] colors, float[] Positio NS, Shader.tilemode tile)
X0: Gradient Initial point coordinate x position
Y0: Gradient initial point coordinate y position
X1: Gradient End coordinate x position
Y1: Gradient end coordinate y position
Colors: array of gradient colors
Positions: This is also an array used to specify the relative position of the color array if NULL is evenly distributed along the slope line
Tile: Tiling mode
[Java]View PlainCopy
- Public lineargradient (float x0, float y0, float x1, float y1, int color0, int Color1, Shader.ti Lemode tile)
X0: Gradient Initial point coordinate x position
Y0: Gradient initial point coordinate y position
X1: Gradient End coordinate x position
Y1: Gradient end coordinate y position
Color0: Gradient Start color
Color1: Gradient End Color
Tile: Tiling mode
LinearGradient is a linear gradient with the following usage:
Gradient is based on the shader class, so we use the Setshader method of paint to set this gradient, the code is as follows:
Paint p=new paint ();
LinearGradient lg=new Lineargradien (0,0,100,100,color.red,color.blue,shader.tilemode.mirror);
Gradient is based on the shader class, so we use the Setshader method of paint to set this gradient, the code is as follows:
P.setshader (LG);
Canvas.drawcicle (0,0,200,P); Parameter 3 is the radius of the circle, and the type is float type.
Android Learning note Advanced 15 shader rendering