流程
使用
- 要素
- 保存像素的bitmgap: A Bitmap to hold the pixeles
- 画笔Paint: A Paint to describe the colors and styles for drawing
- 绘制图像: A drawing primitive (e.g. Rect, Path, text, Bitmap)
- canvas画布,用来在Bitmap上使用Paint绘制内容:A Canvas to host the draw calls (writing into the bitmap)
- Summary
- Canvas.EdgeType
-
Canvas.VertexMode
- Canvas()
- Canvas(Bitmap bitmap)
- Method
- clipPath(Path path, Region.Op op) : 裁剪为指定的路径
- clipPath(Path path) : Intersect the current clip with eht specified path 横切为指定路径
- clipRect :裁剪为指定矩形
- clipRegion : >= API 21 deprecated
-
concat(Matrix matrix) : preconcat the current matrix with the specified matrix
- drawARGB :使用指定颜色填充canvas bitmap
- drawArc : 绘制弧,扇形,弓形等
- drawBitmap
- drawCircle : 绘制圆或圈
- drawLine : 绘制线
- drawOval : 绘制椭圆
- drawRect
- drawText
- drawRoundRect
- drawVertices : 绘制顶点
-
drawPicture : 绘制图片
- getMatrix
- setMatrix
- getDensity
- setDensity
- getBitmap
- setBitmap
- getDrawFilteg
-
setDrawFilter
- restore :
- save
-
saveLayer
- rotate
- scale
- translate
- skew(扭曲)
ColorFilter
A color filter can be used with a Paint to modify th color of each pixel drawn with that paint. Abstract class
ColorMatrix
ComposePathEffect ComposePathEffect (PathEffect outerpe, PathEffect innerpe) Construct a PathEffect whose effect is to apply first the inner effect and the the outer pathEffect (e.g. outer(inner(path))).
Outline : Defines a simple shape, used for bounding graphical regions. `
Shader
- getLocalMatrix(Matrix localM)
- setLocalMatrix(Matrix localM)
BitmapShader to draw a bitmap as a texture.
可以通过设置till mode, 重复使用 BitmapShader(Bitmap bitmap, Shader.TileMode tileX, Shader.TileMode tileY);
ComposeGradient 结合Xfermode, 其他两个shader的组合
- ComposeShader(Shader shaderA, Shader shaderB, Xfermode mode)
- ComposeShader(Shader shaderA, Shader shaderB, PorterDuff.Mode mode)
- shaderA 的颜色作为”dst”模式, shaderB “src”
- Xfermode: 两个着色器与颜色结合的模式。如果为null,则为SRC_OVER。
- PorterDuff.Mode: PorterDuff结合的着色器。
LinearGradient
- LinearGradient(float x0, float y0, float x1, float y1, int[] colors, float[] positions, Shader.TileMode tile)
- colors 沿渐变线的颜色分布,postions 每个相应颜色的颜色数组。
- LinearGradient(float x0, float y0, float x1, float y1, int color0开始的颜色, int color1结束的颜色, Shader.TileMode tile)
RadialGradient
- RadialGradient(float centerX, float centerY, float radius, int[] colors, float[] stops, Shader.TileMode tileMode)
- colors 沿圆中心到边缘的颜色分布,stops 可以为null,[0,1f],对应颜色数组。
- RadialGradient(float centerX, float centerY, float radius, int centerColor, int edgeColor, Shader.TileMode tileMode)
SweepGradient 梯度渲染
- SweepGradient(float cx, float cy, int[] colors, float[] positions)
- SweepGradient(float cx, float cy, int color0, int color1)