First, Porterduffxfermode
Porterduffxfermode is similar to the intersection of the data set in the concept of convergence, but the data is taken in two sets, and we take the intersection of two graphs and set, we first look at an Android API demo inside a gold code map
The SRC and DST in the figure are equivalent to two sets in mathematics, and in our code we can manipulate both sets
CANVAS.DRAWSRC ();
Paint.setxfermode (New Porterduffxfermode (PorterDuff.Mode.XXX));
CANVAS.DRAWDST ();
Only need to have our need to set different mode can, from then on, rounded rectangle or something, that is not a thing!
Second, Shader
Shader literal meaning is shader, renderer, there are five subcategories are:
- Bitmapshader
- LinearGradient
- Radialgradient
- Sweepgradient
- Composeshader
1, Bitmapshader: Bitmap rendering, as the name suggests, use Bitmapshader can do some rendering of bitmap shading operations
The construction method is as follows
/**
* @param bitmap bitmap to render
@param tilex x Direction rendering mode
* @param Tiley y-Direction rendering mode.
* Public
Bitmapshader (Bitmap Bitmap, Tilemode Tilex, Tilemode Tiley)
The first argument is needless to say, and the second and third rendering modes Tilemode have three optional
①. Clamp: The last pixel of the bitmap is stretched when the bitmap is larger than the graphic hour to be drawn, and the bitmap is clipped according to the drawing shape when the graph is bigger than the one to draw bitmap
Bitmapshader Bitmapshader = new Bitmapshader (bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Paint.setshader (Bitmapshader);
Canvas.drawrect (0, 0, bitmap.getwidth () * 2, Bitmap.getheight () * 2, paint);
Bitmapshader Bitmapshader = new Bitmapshader (bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Paint.setshader (Bitmapshader);
RECTF rect = new RECTF (+, +,);
Canvas.drawroundrect (rect, 30,paint);
②. REPEAT: When the bitmap is more vertically repetitive than the hours of graphics to be drawn bitmap; When bitmap is larger than the graphic to be drawn, it is clipped according to the drawing graph bitmap
Bitmapshader Bitmapshader = new Bitmapshader (bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
Paint.setshader (Bitmapshader);
Canvas.drawrect (0, 0, bitmap.getwidth () *2, Bitmap.getheight () * 2, paint);
③. MIRROR: Similar to repeat, when bitmap is more vertically repetitive than the hours of graphics to be drawn bitmap, the difference is that the adjacent two bitmap mirror each other
Bitmapshader Bitmapshader = new Bitmapshader (bitmap, Shader.TileMode.MIRROR, Shader.TileMode.MIRROR);
Paint.setshader (Bitmapshader);
Canvas.drawrect (0, 0, bitmap.getwidth () * 4, Bitmap.getheight () * 4, paint);
When you're familiar with Bitmapshader, rounded-corner pictures, rounded heads, whatever.
1.LinearGradient linear Gradient
Let's look at how it's structured.
/**
* Create a lineargradient
@param x0 start x coordinate
@param y0 start y coordinate
@param x1 End x coordinate
@param y1 end y coordinate
@param Color0 Start color value
@param color1 End color value
@param tile shader mode
/public
lineargradient (float x0, float y0, Float x1, float y1, int color0, int color1,tilemode tile)
lineargradient (float x0, float y0, float x1, float y1, int[ ] colors, float[] positions, Shader.tilemode tile)
Two constructs are similar, the second one can simply add more colors, encapsulate the color values into the array colors, followed by the positions of the colors for the color, and if NULL, the color values are evenly distributed.
LinearGradient and Bitmapshader have three Tilemode optional clamp, REPEAT, MIRROR. The effect of the implementation is as follows:
①clamp
LinearGradient lg = new LinearGradient (0, 0,,, 0xffff0000, 0XFF0000FF, Shader.TileMode.CLAMP);
Paint.setshader (LG);
Canvas.drawrect (0, 0, canvas.getwidth (), Canvas.getheight (), paint);
②repeat
LinearGradient lg = new LinearGradient (0, 0,,, 0xffff0000, 0XFF0000FF, Shader.TileMode.REPEAT);
Paint.setshader (LG);
Canvas.drawrect (0, 0, canvas.getwidth (), Canvas.getheight (), paint);
③mirror
LinearGradient lg = new LinearGradient (0, 0,,, 0xffff0000, 0XFF0000FF, Shader.TileMode.MIRROR);
Paint.setshader (LG);
Canvas.drawrect (0, 0, canvas.getwidth (), Canvas.getheight (), paint);
There are three shader did not introduce, feel a little bit longer, stay to the next one to explain to everyone, I hope you continue to pay attention.