PathEffect 路径效果
PathEffect是Paint中对象的基类,这些对象在被Canvas的矩阵变换和绘制之前会影响绘图原本的几何体。
public class PathEffect {
protected void finalize() throws Throwable {
nativeDestructor(native_instance);
native_instance = 0; // 其他的finalizers仍然可以调用我们。
}
private static native void nativeDestructor(long native_patheffect);
long native_instance;
}
CornerPathEffect 圆角路径效果
public class CornerPathEffect extends PathEffect {
/**
* 通过将线段之间的任何锐角替换为指定半径的圆角来转换绘制的几何图形(STROKE或FILL样式)。
* @param radius 使线段之间的锐角变圆。
*/
public CornerPathEffect(float radius) {
native_instance = nativeCreate(radius);
}
private static native long nativeCreate(float radius);
}
DiscretePathEffect 偏离路径效果
public class DiscretePathEffect extends PathEffect {
/** 将路径切割成分段长度的直线,通过偏差随机偏离原始路径。 */
public DiscretePathEffect(float segmentLength, float deviation) {
native_instance = nativeCreate(segmentLength, deviation);
}
private static native long nativeCreate(float length, float deviation);
}
DashPathEffect 虚线路径效果
public class DashPathEffect extends PathEffect {
/**
* 间隔(intervals)数组必须包含偶数个条目(>=2),偶数索引指定“开”间隔,奇数索引指定“关”间隔。
* 相位(phase)是间隔数组的偏移量(mod所有间隔的总和)。
* 间隔数组控制虚线的长度。Paint的笔划宽度控制虚线的厚度。
* Note: this patheffect only affects drawing with the paint's style is set
* to STROKE or FILL_AND_STROKE. It is ignored if the drawing is done with
* style == FILL.
* 注意:此PathEffect仅影响将Paint的Style设置为STROKE或FILL_AND_STROKE的绘制。
* 如果使用Style==FILL完成绘图,则忽略此选项。
* @param intervals “开”“关”距离数组
* @param phase 偏移到间隔数组中
*/
public DashPathEffect(float intervals[], float phase) {
if (intervals.length < 2) {
throw new ArrayIndexOutOfBoundsException();
}
native_instance = nativeCreate(intervals, phase);
}
private static native long nativeCreate(float intervals[], float phase);
}
PathDashPathEffect 路径虚线路径效果
public class PathDashPathEffect extends PathEffect {
public enum Style {
TRANSLATE(0), //!< 将形状平移到每个位置
ROTATE(1), //!< 围绕其中心旋转形状
MORPH(2); //!< 使每个点改变形态,并将直线转换为曲线
Style(int value) {
native_style = value;
}
int native_style;
}
/**
* 用指定的形状将绘制的路径盖上。这仅适用于Paint的Style为STROKE或STROKE_AND_FILL的情况。
* 如果Paint的Style为FILL,则忽略此效果。Paint的strokeWidth不会影响结果。
*/
public PathDashPathEffect(Path shape, float advance, float phase,
Style style) {
native_instance = nativeCreate(shape.readOnlyNI(), advance, phase,
style.native_style);
}
private static native long nativeCreate(long native_path, float advance,
float phase, int native_style);
}
ComposePathEffect 组合路径效果
public class ComposePathEffect extends PathEffect {
/**
* 构造一个PathEffect,其效果是首先应用内部效果和外部PathEffect(例如outer(inner(path)))。
*/
public ComposePathEffect(PathEffect outerpe, PathEffect innerpe) {
native_instance = nativeCreate(outerpe.native_instance,
innerpe.native_instance);
}
private static native long nativeCreate(long nativeOuterpe,
long nativeInnerpe);
}
SumPathEffect 组合路径效果
public class SumPathEffect extends PathEffect {
/**
* 构造一个PathEffect,其效果是按顺序应用两个效果。(例如,first(path) + second(path))
*/
public SumPathEffect(PathEffect first, PathEffect second) {
native_instance = nativeCreate(first.native_instance,
second.native_instance);
}
private static native long nativeCreate(long first, long second);
}