PathEffect
PathEffect is the base class for objects in the Paint that affect the geometry of a drawing primitive before it is transformed by the canvas' matrix and drawn.
PathEffect一般是需要配合Paint来使用,会在Canvas的变换操作之前影响绘画的效果。
PathEffect本身是没有实现什么效果的,只是一个简单的基类,不过android.graphics提供了集中常见的效果,系统为了高效的实现不同效果,它们的实现都封装在native中。
- CornerPathEffect 线条的交汇角效果
- DashPathEffect 线条的虚线效果
- DiscretePathEffect 线条的离散
- PathDashPathEffect 使用Path做虚线的效果(Path可以画图像)
- ComposePathEffect 组合两种效果
- SumPathEffect 叠加向后纵效果
1.默认效果
2.CornerPathEffect
- radius 圆角的半径
CornerPathEffect(float radius)
mPaint.setPathEffect(new CornerPathEffect(16));
3.DashPathEffect
- intervals on/off(显示部分和空白部分)的成对值,所以至少需要两个以上的数值,可以实现不同的虚线效果
- phase 偏移值
DashPathEffect(float intervals[], float phase)
mPaint.setPathEffect(new DashPathEffect(new float[]{8,4,16,4},6));
4.DiscretePathEffect
- segmentLength 离散的片段最大长度
- deviation 随机的最大偏移量
DiscretePathEffect(float segmentLength, float deviation)
mPaint.setPathEffect(new DiscretePathEffect(16,16));
5.PathDashPathEffect
- shape Path画的图形
- advance 间隔
- phase 偏移
- style 样式
- TRANSLATE 直接平移
- ROTATE旋转成跟路径一致的方向
- MORPH 衔接线条交汇处,但是有可能会拉伸
PathDashPathEffect(Path shape, float advance, float phase,Style style)
mPaint.setPathEffect(new PathDashPathEffect(mRectItem, 16, 36, PathDashPathEffect.Style.TRANSLATE));
6.ComposePathEffect
先应用inner效果,再应用outer效果,等于outer(inner(path)
ComposePathEffect(PathEffect outerpe, PathEffect innerpe)
mPaint.setPathEffect(new ComposePathEffect(
new CornerPathEffect(24),
new DiscretePathEffect(16,16)
));
7.ComposePathEffect
两个效果相加 ,等于first(path) + second(path)
蛋疼的是还没能组合出理想的效果
SumPathEffect(PathEffect first, PathEffect second)
mPaint.setPathEffect(new SumPathEffect(
new PathDashPathEffect(mCircleItem, 12, 0, PathDashPathEffect.Style.TRANSLATE),
new DiscretePathEffect(16,24)
));