Path
路径,可用于绘制直线、曲线构成几何路径,还可以用于根据路径绘制文字。
常用api
移动、连线、闭合、添加图形等。
//移动到某个点
path.moveTo(100f,100f)
//连线到绝对点
path.lineTo(200f,200f)
path.lineTo(250f,200f)
//连线到相对上一个终点移动多少偏移量
path.rLineTo(10f,30f)
//添加曲线
path.addArc(200f,200f,400f,400f,-220f,220f)
//添加曲线
path.addArc(200f,200f,400f,400f,-220f,220f)
path.addRect(50f,50f,200f,200f,Path.Direction.CW)
path.addCircle(50f,50f,100f,Path.Direction.CW)
path.addOval(10f,10f,100f,200f,Path.Direction.CW)
//闭合曲线
path.close()
canvas?.drawPath(path,paint)
addArc和arcTo的区别
//添加曲线
//Add the specified arc to the path as a new contour.
//float left, float top, float right, float bottom, float startAngle, float sweepAngle
path.addArc(200f,200f,400f,400f,-220f,220f)
//Append the specified arc to the path as a new contour.
//float left, float top, float right, float bottom, float startAngle,float sweepAngle, boolean forceMoveTo
path.arcTo()
//arcTo多了一个参数,如果为false,那和addArc()效果一样,如果为true,
//那需要在前面path的终点加上一条直线连接到当前arc的起点,即自动lineTo()
其他功能:
var path2 = Path()
path2.moveTo(100f,100f)
path2.lineTo(110f,100f)
//添加另一条path
path.addPath(path2)
//添加圆角矩形
var rect = RectF(200f,200f,300f,300f)
path.addRoundRect(rect,20f,20f,Path.Direction.CW)
//移动到某个点
path.moveTo(300f,500f)
//二阶贝塞尔曲线
path.quadTo(500f,100f,800f,500f)
//相对位置的二阶贝塞尔曲线
path.rQuadTo(200f,-400f,500f,0f)
//三阶贝塞尔曲线cubicTo(float x1, float y1, float x2, float y2, float x3, float y3)
网友评论