Paint - PathEffect 詳解

PathEffect

image.png

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.

該系列類沒有實例方法,只有構造方法,只須要構造後,傳入 Paint.setPathEffect(PathEffect effect) 便可。


概覽
java

image.png



原圖:
image.png

CornerPathEffect

CornerPathEffect(float radius)android

Parameters
radius float: Amount to round sharp angles between line segments.

Transforms geometries that are drawn (either STROKE or FILL styles) by replacing any sharp angles between line segments into rounded angles of the specified radius.git

image.png

DiscretePathEffect

DiscretePathEffect(float segmentLength, float deviation)github

Parameters
segmentLength float
deviation float

Chop the path into lines of segmentLengthdeviation**.canvas

segmentLength=1dp, deviation=10dp
app

image.png

segmentLength=10dp, deviation=10dp
this

image.png

DashPathEffect

DashPathEffect(float[] intervals, float phase)spa

Parameters
intervals float: array of ON and OFF distances
phase float: offset into the intervals array
總體偏移, 動態設置 phase, 能夠產生螞蟻線效果

The intervals array must contain an even number of entries (>=2), with the even indices specifying the "on" intervals, and the odd indices specifying the "off" intervals.
phase is an offset into the intervals array (mod the sum of all of the intervals).
The intervals array controls the length of the dashes. The paint's strokeWidth controls the thickness of the dashes.
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.code

image.png

PathDashPathEffect

PathDashPathEffect(Path shape, float advance, float phase, PathDashPathEffect.Style style)orm

Parameters
shape Path: The path to stamp along
shape 須要是閉合路徑
advance float: spacing between each stamp of shape
shape 之間的間距, 忽略 shape 自己的大小
phase float: amount to offset before the first shape is stamped
總體偏移, 動態設置 phase, 能夠產生螞蟻線效果
style PathDashPathEffect.Style: how to transform the shape at each position as it is stamped
枚舉取值: MORPH, ROTATE, TRANSLATE
MORPH: 方向跟路徑一致, 在拐角處變形
ROTATE: 方向跟路徑一致, 拐角處保持不變, 有斷開效果
TRANSLATE: 保持shape方向不變, 不隨路徑變化
MORPH 效果最好

Dash the drawn path by stamping it with the specified shape.
This only applies to drawings when the paint's style is STROKE or STROKE_AND_FILL. If the paint's style is FILL, then this effect is ignored.
The paint's strokeWidth does not affect the results.

MORPH

image.png

ROTATE

image.png

TRANSLATE

image.png

SumPathEffect

SumPathEffect(PathEffect first, PathEffect second)

Construct a PathEffect whose effect is to apply two effects, in sequence. (e.g. first(path) + second(path))
將兩個 PathEffect 效果疊加,至關與繪製了2次。firstsecond 的順序無影響。

DashPathEffect + CornerPathEffect

image.png

ComposePathEffect

ComposePathEffect(PathEffect outerpe, PathEffect innerpe)

Construct a PathEffect whose effect is to apply first the inner effect and the the outer pathEffect. (e.g. outer(inner(path)))
將兩個 PathEffect 效果進行組合,先進行 innerpe,在此次的結果上在進行 outerpe。兩次的順序不一樣,結果也有差別。

CornerPathEffect(DashPathEffect())

image.png

DashPathEffect(CornerPathEffect())

image.png

源碼

github.com/wenmin92/An…

相關文章
相關標籤/搜索