Android Learning note Advanced 15 shader rendering

Source: Internet
Author: User

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
    1. 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
    1. 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

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.