【Android】【绘图】Path的基本API使用

		//Path的基本使用
		//绘制直线
		Path path = new Path();
		path.moveTo(200, 200); //移动到起点
		path.lineTo(300, 300); //画线
		path.lineTo(300, 500); //画线
		path.lineTo(20, 500); //画线
		path.close(); //闭合
		textPaint.setStyle(Paint.Style.FILL);
		canvas.drawPath(path, textPaint);
		textPaint.setStyle(Paint.Style.STROKE);
		textPaint.setColor(ColorUtil.RED);
		canvas.drawPath(path, textPaint);
		//绘制矩形
		Path p1 = new Path();
		RectF rect = new RectF(100, 200, 400, 400);
		p1.addRect(rect, Path.Direction.CCW); //逆时针
		canvas.drawPath(p1, linePaint);
		canvas.drawTextOnPath("12345678901234567890", p1, 0, 0, textPaint);
		Path p2 = new Path();
		RectF rect1 = new RectF(500, 200, 800, 400);
		p2.addRect(rect1, Path.Direction.CW); //顺时针
		canvas.drawPath(p2, linePaint);
		canvas.drawTextOnPath("12345678901234567890", p2, 0, 0, textPaint);
		//绘制其它图形
		//可以类比Canvas的API来类推
		Path path = new Path();
		path.addRoundRect();
		path.addCircle();
		path.addOval();
		path.addArc();
		//绘制二阶贝塞尔曲线
		Path path = new Path();
		path.moveTo(300,700); //起点
		path.quadTo(500,200,600,700); //绝对坐标,控制点,终点
		path.quadTo(700,900,800,700); //绝对坐标,控制点,终点
		canvas.drawPath(path,linePaint);
		Path path = new Path();
		path.moveTo(300,700); //起点
		path.rQuadTo(100,-100,200,0); //相对坐标,控制点,终点
		path.rQuadTo(100,100,200,0); //相对坐标,控制点,终点
		canvas.drawPath(path,linePaint);

你可能感兴趣的:(android)