Shader
Bitmapshader, the Shader family specializes in image rendering.
Construction Method:
Bitmapshader (Bitmap Bitmaptilemode tilextilemode Tiley)
Bitmap: Original
Tiles are literal , tiles. The tilemode here can be seen as a pattern of paving.
Tilex, pattern of tiley:x/y direction paving
public enum Tilemode { CLAMP (0), REPEAT (1), MIRROR (2); Tilemode (int nativeint) { this.nativeint = nativeint; } final int nativeint;}
CLAMP: If the original bounds (that is, the border of the artwork) is exceeded, the color on the repeating edge
REPEAT: Repeat Bitmap
MIRROR: Repeat bitmap, unlike repeat, it is a mirror repetition, namely: reverse repetition
Cases:
public class Bitmapshaderview extends View { private bitmapshader mbitmapshader; Private shapedrawable mshapedrawable; Public Bitmapshaderview (context context, Bitmap Bitmap) { super (context); Mbitmapshader = new Bitmapshader (bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); mshapedrawable = new Shapedrawable (new OvalShape ()); Mshapedrawable.getpaint (). Setshader (Mbitmapshader);// mshapedrawable.setbounds (0, 0, bitmap.getwidth (), Bitmap.getheight ()); Original size mshapedrawable.setbounds (0, 0, bitmap.getwidth () * 2, Bitmap.getheight () * 2); } @Override protected void OnDraw (canvas canvas) { super.ondraw (canvas); Canvas.drawcolor (Color.cyan); Mshapedrawable.draw (canvas);} }
In the activity, Setcontentview (new Bitmapshaderview (context, bitmap));
Original
X and y edges repeat
Change: Mbitmapshader = new Bitmapshader (bitmap, Shader.TileMode.MIRROR, Shader.TileMode.REPEAT);
Effect
X-direction Mirror Repeat, y-direction repeat
Change: Mbitmapshader = new Bitmapshader (bitmap, Shader.TileMode.REPEAT, Shader.TileMode.MIRROR);
Effect:
Repeat in x direction, mirror repeat in y direction
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android Shader renderer: Bitmapshader