Android Path 类学习

这是 Kevin 的一篇 Google Android API 的翻译习作,原文请移步:

Android Deveolopers Path 类 api


public class
公共类

Path

extends Object
继承 Object

java.lang.Object
   ↳ android.graphics.Path

Class Overview
类 概貌


The Path class encapsulates compound (multiple contour) geometric paths consisting of straight line segments, quadratic curves, and cubic curves. It can be drawn with canvas.drawPath(path, paint), either filled or stroked (based on the paint’s Style), or it can be used for clipping or to draw text on a path.

Path类封装了由直线段,二次曲线,三次曲线混合(多轮廓)组成的几何路径。它可以通过 canvas.drawPath(path, paint) 进行绘制,包括填充和描边(取决于 paint’s Style 这个参数),或者它可以用于裁剪或绘制路径上的文本。

Summary
概要


Nested Classes
嵌套类
enum Path.Direction Specifies how closed shapes (e.g. rects, ovals) are oriented when they are added to a path.
指定封闭的形状(如矩形的,椭圆形),当它们被添加到路径时的方向。有顺时针和逆时针两个数值。
enum Path.FillType Enum for the ways a path may be filled
填充方式的枚举类型:Path.FillType EVEN_ODD,用奇偶规则填充
Path.FillType INVERSE_EVEN_ODD,顾名思义,和EVEN_ODD规则恰好相反。
Path.FillType INVERSE_WINDING,同样,WINDING的反效果。
Path.FillType WINDING,用非零环绕数规则填充。
Public Constructors
公共构造函数
Path()

Create an empty path
创建一个空的 path
Path(Path src)

Create a new path, copying the contents from the src path.
复制 Path src 到一个新的 path
Public Methods
公共类
void addArc(RectF oval, float startAngle, float sweepAngle)

Add the specified arc to the path as a new contour.
将一个指定的弧形作为新的轮廓添加到 path
void addCircle(float x, float y, float radius, Path.Direction dir)

Add a closed circle contour to the path
添加一个闭合圆形轮廓到 path
void addOval(RectF oval, Path.Direction dir)

Add a closed oval contour to the path
添加一个闭合的椭圆形轮廓到 path
void addPath(Path src, float dx, float dy)

Add a copy of src to the path, offset by (dx,dy)
将源 path 拷贝一份并添加到  path(当前),dx, dy 为偏移
void addPath(Path src)

Add a copy of src to the path
将源 path 拷贝一份并添加到  path(当前)
void addPath(Path src, Matrix matrix)

Add a copy of src to the path, transformed by matrix
将源 path 拷贝一份并添加到  path(当前),由 matrix 进行转换
void addRect(float left, float top, float right, float bottom, Path.Direction dir)

Add a closed rectangle contour to the path
添加一个闭合的矩形轮廓到 path
void addRect(RectF rect, Path.Direction dir)

Add a closed rectangle contour to the path
添加一个闭合的矩形轮廓到 path
void addRoundRect(RectF rect, float[] radii, Path.Direction dir)

Add a closed round-rectangle contour to the path.
添加一个闭合的圆角矩形轮廓到 path
void addRoundRect(RectF rect, float rx, float ry, Path.Direction dir)

Add a closed round-rectangle contour to the path
添加一个闭合的圆角矩形轮廓到 path
void arcTo(RectF oval, float startAngle, float sweepAngle)

Append the specified arc to the path as a new contour.
追加指定的弧形到 path 作为一个新的轮廓
void arcTo(RectF oval, float startAngle, float sweepAngle, boolean forceMoveTo)

Append the specified arc to the path as a new contour.
追加指定的弧形到 path 作为一个新的轮廓
void close()

Close the current contour.
闭合当前轮廓
void computeBounds(RectF bounds, boolean exact)

Compute the bounds of the control points of the path, and write the answer into bounds.
计算路径的控制点的边界,并把答案写进边界
void cubicTo(float x1, float y1, float x2, float y2, float x3, float y3)

Add a cubic bezier from the last point, approaching control points (x1,y1) and (x2,y2), and ending at (x3,y3).
从上一个点添加一个三次贝塞尔曲线,经过控制点(x1, y1), (x2, y2),在(x3, y3) 结束
Path.FillType getFillType()

Return the path’s fill type.
返回 path 的填充类型
void incReserve(int extraPtCount)

Hint to the path to prepare for adding more points.
对 path 暗示将会添加更多的点
boolean isEmpty()

Returns true if the path is empty (contains no lines or curves)
当 path 为空时返回 true (包括没有线和曲线)
boolean isInverseFillType()

Returns true if the filltype is one of the INVERSE variants
如果填充类型为 INVERSE 变量的其中一种,返回 true
boolean isRect(RectF rect)

Returns true if the path specifies a rectangle.
如果 path 指定一个矩形,返回 true
void lineTo(float x, float y)

Add a line from the last point to the specified point (x,y).
从上一点到 (x, y) 画线
void moveTo(float x, float y)

Set the beginning of the next contour to the point (x,y).
将下一个轮廓的起点设置为 (x, y)
void offset(float dx, float dy, Path dst)

Offset the path by (dx,dy), returning true on success
将 path 偏移 (x, y),成功则返回 true
void offset(float dx, float dy)

Offset the path by (dx,dy), returning true on success
将 path 偏移 (x, y),成功则返回 true
void quadTo(float x1, float y1, float x2, float y2)

Add a quadratic bezier from the last point, approaching control point (x1,y1), and ending at (x2,y2).
从上一个点添加一个二次贝塞尔曲线,经过控制点(x1, y1),在(x2, y2) 结束
void rCubicTo(float x1, float y1, float x2, float y2, float x3, float y3)

Same as cubicTo, but the coordinates are considered relative to the current point on this contour.
同 cublicTo,但坐标被认为是相对于当前轮廓上的当前点。
void rLineTo(float dx, float dy)

Same as lineTo, but the coordinates are considered relative to the last point on this contour.
同 lineTo,但坐标被认为是相对于当前轮廓上的上一点。
void rMoveTo(float dx, float dy)

Set the beginning of the next contour relative to the last point on the previous contour.
设置下一个轮廓的开始点相当于上一个轮廓的最后一点
void rQuadTo(float dx1, float dy1, float dx2, float dy2)

Same as quadTo, but the coordinates are considered relative to the last point on this contour.
同 quadTo,但坐标被认为是相对于当前轮廓上的上一点。
void reset()

Clear any lines and curves from the path, making it empty.
清空 path 里面的所有线和曲线
void rewind()

Rewinds the path: clears any lines and curves from the path but keeps the internal data structure for faster reuse.
清空 path 中的所有线和曲线,但是保留其内部数据以便快速重用
void set(Path src)

Replace the contents of this with the contents of src.
用源 path 代替当前 path 的内容
void setFillType(Path.FillType ft)

Set the path’s fill type.
设置 path 填充类型
void setLastPoint(float dx, float dy)

Sets the last point of the path.
设置 path 的最后一点
void toggleInverseFillType()

Toggles the INVERSE state of the filltype
切换 filltype 的逆状态
void transform(Matrix matrix, Path dst)

Transform the points in this path by matrix, and write the answer into dst.
应用矩阵变换当前 path, 并把结果写到目的 path
void transform(Matrix matrix)

Transform the points in this path by matrix.
应用矩阵变换当前 path
Protected Methods
私有方法
void finalize()

Invoked when the garbage collector has detected that this instance is no longer reachable.
当垃圾收集器检测到该实例不再可达时调用

《Android Path 类学习》上有1条评论

kevin进行回复 取消回复

电子邮件地址不会被公开。 必填项已用*标注