1. FillType
path的填充方式,有4種,舉例說明啥效果
/**
* Enum for the ways a path may be filled.
*/
public enum FillType {
// these must match the values in SkPath.h
/**
* Specifies that "inside" is computed by a non-zero sum of signed
* edge crossings.
*/
WINDING (0),
/**
* Specifies that "inside" is computed by an odd number of edge
* crossings.
*/
EVEN_ODD (1),
/**
* Same as {@link #WINDING}, but draws outside of the path, rather than inside.
*/
INVERSE_WINDING (2),
/**
* Same as {@link #EVEN_ODD}, but draws outside of the path, rather than inside.
*/
INVERSE_EVEN_ODD(3);
FillType(int ni) {
nativeInt = ni;
}
final int nativeInt;
}
1.1 WINDING
默認值就是這個,測試代碼如下,數學裏的並集,屬於A或者屬於B的部分
path2.apply {
reset()
addCircle(100f,100f,50f,Path.Direction.CW)
}
path3.apply {
reset()
addCircle(200f,200f,50f,Path.Direction.CW)
}
path.apply {
reset()
path.addPath(path2)
path.fillType=Path.FillType.WINDING
path.addPath(path3)
}
1.2 INVERSE_WINDING
上邊的效果取反,
測試代碼
path2.apply {
reset()
addCircle(100f,100f,50f,Path.Direction.CW)
}
path3.apply {
reset()
addCircle(200f,200f,50f,Path.Direction.CW)
}
path.apply {
reset()
path.addPath(path2)
path.fillType=Path.FillType.INVERSE_WINDING
path.addPath(path3)
}
canvas.drawPath(path,p)
1.3 EVEN_ODD
把交集扣掉,也就是把兩者共有的部分扣掉
path3.apply {
reset()
addCircle(200f,200f,50f,Path.Direction.CW)
}
path4.apply {
reset()
addCircle(280f,200f,60f,Path.Direction.CW)
}
path.apply {
reset()
path.addPath(path3)
path.fillType=Path.FillType.EVEN_ODD
path.addPath(path4)
}
1.4 INVERSE_EVEN_ODD
上邊的效果取反