Canvas,Paint方法记录(一)

来源:互联网 发布:手机修改图片软件 编辑:程序博客网 时间:2024/06/11 20:29

Canvas,Paint方法记录


Canvas.draw*

Paint基础:

Paint.setStyle(Style style) 设置绘制模式
Paint.setColor(int color) 设置颜色
Paint.setStrokeWidth(float width) 设置线条宽度
Paint.setTextSize(float textSize) 设置文字大小
Paint.setAntiAlias(boolean aa) 设置抗锯齿开关–一般打开

方法列表:

1.画圆 drawCircle(float cx, float cy, float radius, Paint paint) cx,cy为圆形的坐标 radius:半径
2.画矩形 drawRect(float left, float top, float right, float bottom, Paint paint) float left, float top, float right, float bottom 矩形四条变相对x轴y轴的距离,可替换为RectF
3.画椭圆 drawOval 与画 圆形同理
4.画扇形 drawArc(RectF oval, float startAngle, float sweepAngle, boolean useCenter,Paint paint) startAngle:开始读书,0位与 x轴平行 sweepAngle:delta角度,顺时针 userCenter :画的形状是否连接到圆形
5.画点 drawPoint(float x, float y, Paint paint)
6.画线 drawLine(float startX, float startY, float stopX, float stopY,Paint paint)
drawLines(@Size(multiple=4) float[] pts, Paint paint) 每四个值分别作为 startX,startY,stopX,stopY.依次读取出来进行画线
7.画路径 drawPath(path) 其中有方法
Path path = new Path(); // 初始化 Path 对象
第一组: addXxx() ——添加子图形
如, addCircle(float x, float y, float radius, Direction dir) 添加圆
addOval(float left, float top, float right, float bottom, Direction dir)
addOval(RectF oval, Direction dir) 添加椭圆
addRect(float left, float top, float right, float bottom, Direction dir)
addRect(RectF rect, Direction dir) 添加矩形
addRoundRect(RectF rect, float rx, float ry, Direction dir)
addRoundRect(float left, float top, float right, float bottom, float rx, float ry, Direction dir)
addRoundRect(RectF rect, float[] radii, Direction dir)
addRoundRect(float left, float top, float right, float bottom, float[] radii, Direction dir) 添加圆角矩形
addPath(Path path) 添加另一个 Path
第二组:xxxTo() ——画线(直线或曲线)
1.lineTo(x, y) 的参数是绝对坐标,而 rLineTo(x, y) 的参数是相对当前位置的相对坐标 (前缀 r 指的就是 relatively 「相对地」)。
2.quadTo(float x1, float y1, float x2, float y2) / rQuadTo(float dx1, float dy1, float dx2, float dy2) 画二次贝塞尔曲线
3.cubicTo(float x1, float y1, float x2, float y2, float x3, float y3) / rCubicTo(float x1, float y1, float x2, float y2, float x3, float y3) 画三次贝塞尔曲线和上面这个 4.quadTo() rQuadTo() 的二次贝塞尔曲线同理,cubicTo() 和 rCubicTo() 是三次贝塞尔曲线。
5.moveTo(float x, float y) / rMoveTo(float x, float y) 移动起点到目标位置
不论是直线还是贝塞尔曲线,都是以当前位置作为起点,而不能指定起点。但你可以通过 moveTo(x, y) 或 rMoveTo() 来改变当前位置,从而间接地设置这些方法的起点。
6.arcTo(RectF oval, float startAngle, float sweepAngle, boolean forceMoveTo)
7.arcTo(float left, float top, float right, float bottom, float startAngle, float sweepAngle, boolean forceMoveTo) / arcTo(RectF oval, float startAngle, float sweepAngle) 画弧形这个方法和 Canvas.drawArc() 比起来,少了一个参数 useCenter,而多了一个参数 forceMoveTo 。少了 useCenter ,是因为 arcTo() 只用来画弧形而不画扇形,所以不再需要 useCenter 参数;而多出来的这个 forceMoveTo 参数的意思是,绘制是要「抬一下笔移动过去」,还是「直接拖着笔过去」,区别在于是否留下移动的痕迹。
8.drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint)
drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint)
画图
9.drawText(String text, float x, float y, Paint paint) 绘制文字
原创粉丝点击