Shader着色器是计算机图形学中的概念。在Android开发中,Shader的主要用法是:
paint.setShader(shader);
canvas.drawXxx(xx, xx, xx, xx, paint);
shader就是着色器。paint就是涂料的意思。canvas是画布的意思。
通俗地说,shader就像是钢笔,paint就像是钢笔内的墨水,canvas就像是书写的纸张。
Shader有三种模式:
public enum TileMode {
/**
* replicate the edge color if the shader draws outside of its
* original bounds
*/
CLAMP (0),
/**
* repeat the shader's image horizontally and vertically
*/
REPEAT (1),
/**
* repeat the shader's image horizontally and vertically, alternating
* mirror images so that adjacent images always seam
*/
MIRROR (2);
TileMode(int nativeInt) {
this.nativeInt = nativeInt;
}
final int nativeInt;
}
CLAMP:延申边缘的像素。
REPEAT:重复shader的内容。
MIRROR:镜像重复shader的内容。
Shader有以下五个子类:
BitmapShader: 位图渲染
LinearGradient: 线性渲染
SweepGradient: 梯度渲染
RadialGradient: 光束渲染
ComposeShader: 组合渲染