Path高级操作
-Path常用操作
作用 | 相关方法 | 备注 |
---|---|---|
rXxx方法 | rMoveTo,rLineTo,rQuadTo,rCubicTo | 不带r的方法是基于原点的坐标系,rXxx是基于当前点的坐标系 |
填充模式 | setFillType,getFillType, isInverseFillType,toggleInverseFillType |
设置,获取,判断和切换填充模式 |
提示方法 | incReserve | 提示Path还有多少个点等待加入 |
布尔操作API19 | op | 对两个Path进行布尔运算(差集,交集,并集,异或) |
计算边界 | computeBounds | 计算Path的边界 |
重置路径 | reset,rewind | 清除Path的内容, reset不保留内部数据结构,但保留FillType rewind保留内部数据结构,但不保留FillType |
矩阵操作 | transform | 矩阵变换 |
-Path方法详解
rXxx
path.moveTo(100,100);
path.rLineTo(100,200);
canvas.drawPath(path,mDeafultPaint);
填充模式
填充模式未完全理解
布尔操作
Path path1 = new Path();
Path path2 = new Path();
Path path3 = new Path();
Path path4 = new Path();
path1.addArc(-200,-200,200,200,90,180);
path2.addCircle(0,-100,100, Path.Direction.CW);
path3.addCircle(0,100,100,Path.Direction.CW);
path4.addCircle(-100,-100,30, Path.Direction.CW);
path1.op(path2,Path.Op.UNION);
path1.op(path3, Path.Op.DIFFERENCE);
path1.op(path4,Path.Op.DIFFERENCE);
canvas.drawPath(path1, mPaint);
计算边界
//测量结果会放入Rect
void computeBounds (RectF bounds, boolean exact)
代码:
Path path = new Path();
path.lineTo(100,50);
path.lineTo(100,-50);
path.close();
path.addCircle(-100,0,100, Path.Direction.CW);
RectF rectF = new RectF();
path.computeBounds(rectF,true);
canvas.drawPath(path,mPaint);
mPaint.setColor(Color.RED);
mPaint.setStyle(Paint.Style.STROKE);
canvas.drawRect(rectF,mPaint);
结果: