參考:https://blog.csdn.net/harvic880925/article/details/51010839
1.基本屬性
方法 |
名稱 |
取值說(shuō)明 |
setAntiAlias(boolean aa) |
抗鋸齒 |
true 先舷,flase
|
setColor(@ColorInt int color) |
顏色 |
Color.RED ,Color.GREEN ... |
setStyle(Style style); |
填充 |
FILL 填充內(nèi)部,STROKE 僅描邊,FILL_AND_STROKE
|
setStrokeWidth(float width); |
筆寬 |
1234567...Max |
setShadowLayer (float radius, float dx, float dy, int color) |
陰影 |
radius 陰影的傾斜度dx 水平位移dy 垂直位移 |
setPathEffect(PathEffect effect) |
路徑樣式 |
ComposePathEffect, CornerPathEffect, DashPathEffect, DiscretePathEffect, PathDashPathEffect, SumPathEffect
|
2.特殊屬性
方法 |
名稱 |
取值說(shuō)明 |
setStrokeCap(Paint.Cap cap) |
線帽 |
Cap.BUTT 速蕊,Cap.SQUARE 俩功,Cap.ROUND
|
setStrokeJoin(Paint.Join join) |
線段連接樣式 |
Join.MITER ,Join.Round 扔傅,Join.BEVEL
|
setPathEffect(PathEffect effect) |
路徑樣式 |
取值類型是所有派生自PathEffect 的子類 |
-
setStrokeCap(Paint.Cap cap)
線帽
Paint paint = new Paint();
paint.setStrokeWidth(80);
paint.setAntiAlias(true);
paint.setColor(Color.GREEN);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeCap(Paint.Cap.BUTT);
canvas.drawLine(100,200,400,200,paint);
paint.setStrokeCap(Paint.Cap.SQUARE);
canvas.drawLine(100,400,400,400,paint);
paint.setStrokeCap(Paint.Cap.ROUND);
canvas.drawLine(100,600,400,600,paint);
//垂直畫(huà)出x=100這條線
paint.reset();
paint.setStrokeWidth(2);
paint.setColor(Color.RED);
canvas.drawLine(100,100,100,800,paint);
canvas.drawLine(400,100,400,800,paint);
-
setStrokeJoin(Paint.Join join)
線段連接樣式
Paint paint = new Paint();
paint.setStrokeWidth(8);
paint.setColor(Color.GREEN);
paint.setStyle(Paint.Style.STROKE);
Path path = new Path();
path.moveTo(100,600);
path.lineTo(400,100);
path.lineTo(700,600);
canvas.drawPath(path,paint);
paint.setColor(Color.RED);
paint.setPathEffect(new CornerPathEffect(100));
canvas.drawPath(path,paint);
paint.setColor(Color.LTGRAY);
paint.setPathEffect(new CornerPathEffect(300));
canvas.drawPath(path,paint);
Paint paint = new Paint();
paint.setStrokeWidth(100);
paint.setColor(Color.BLACK);
paint.setStyle(Paint.Style.STROKE);
paint.setAntiAlias(true);
Path path = new Path();
path.moveTo(100,200);
path.lineTo(400,200);
path.lineTo(400,400);
paint.setStrokeJoin(Paint.Join.MITER);
canvas.drawPath(path,paint);
path.moveTo(100,500);
path.lineTo(400,500);
path.lineTo(400,700);
paint.setStrokeJoin(Paint.Join.ROUND);
canvas.drawPath(path,paint);
path.moveTo(100,800);
path.lineTo(400,800);
path.lineTo(400,1000);
paint.setStrokeJoin(Paint.Join.BEVEL);
canvas.drawPath(path,paint);
分別為MITER,ROUND,BEVEL,轉(zhuǎn)角不為90的情況
-
setPathEffect(PathEffect effect)
路徑樣式
方法 |
名稱 |
取值說(shuō)明 |
CornerPathEffect |
圓形拐角效果 |
public CornerPathEffect(float radius) radius:即當(dāng)前連接兩條直線所使用的圓的半徑 |
DashPathEffect |
虛線效果 |
public DashPathEffect(float intervals[], float phase) intervals[]:表示組成虛線的各個(gè)線段的長(zhǎng)度耍共;整條虛線就是由intervals[]中這些基本線段循環(huán)組成的。比如铅鲤,我們定義new float[] {20,10}划提;那這個(gè)虛線段就是由兩段線段組成的,第一個(gè)可見(jiàn)的線段長(zhǎng)為20邢享,每二個(gè)線段不可見(jiàn)鹏往,長(zhǎng)度為10。 |
DiscretePathEffect |
離散路徑效果 |
public DiscretePathEffect(float segmentLength, float deviation) 其中segmentLength 表示將原來(lái)的路徑切成多長(zhǎng)的線段,deviation 表示被切成的每個(gè)小線段的偏移距離 |
PathDashPathEffect |
印章路徑效果 |
public PathDashPathEffect(Path shape, float advance, float phase,Style style) |
ComposePathEffect |
合成路徑效果 |
public ComposePathEffect(PathEffect outerpe, PathEffect innerpe) 顯示兩種效果的一條組合路徑 |
SumPathEffect |
求和路徑效應(yīng) |
public SumPathEffect(PathEffect first, PathEffect second) 兩種效果的兩條路徑重疊顯示 |
Path shape:表示印章路徑骇塘,比如我們下面示例中的三角形加右上角一個(gè)點(diǎn)伊履;
float advance:表示兩個(gè)印章路徑間的距離,很容易理解,印章間距離越大款违,間距就越大唐瀑。
float phase:路徑繪制偏移距離,與上面DashPathEffect中的float phase參數(shù)意義相同
Style style:表示在遇到轉(zhuǎn)角時(shí),如何操作印章以使轉(zhuǎn)角平滑過(guò)渡,取值有:Style.ROTATE驱负,Style.MORPH颜武,Style.TRANSLATE;Style.ROTATE表示通過(guò)旋轉(zhuǎn)印章來(lái)過(guò)渡轉(zhuǎn)角淮捆;Style.MORPH表示通過(guò)變形印章來(lái)過(guò)渡轉(zhuǎn)角;Style.TRANSLATE表示通過(guò)位移來(lái)過(guò)渡轉(zhuǎn)角
Path path = new Path();
path.moveTo(100,600);
path.lineTo(400,100);
path.lineTo(700,600);
canvas.drawPath(path,paint);
paint.setColor(Color.RED);
paint.setPathEffect(new CornerPathEffect(100));
canvas.drawPath(path,paint);
paint.setColor(Color.LTGRAY);
paint.setPathEffect(new CornerPathEffect(300));
canvas.drawPath(path,paint);
Path path = new Path();
path.moveTo(100,600);
path.lineTo(300,100);
path.lineTo(600,600);
canvas.drawPath(path,paint);
paint.setColor(Color.RED);
//使用DashPathEffect畫(huà)線段
paint.setPathEffect(new DashPathEffect(new float[]{20,10,100,100},0));
canvas.translate(20,0);
canvas.drawPath(path,paint);
//畫(huà)同一條線段,偏移值為15
paint.setPathEffect(new DashPathEffect(new float[]{20,10,50,100},15));
paint.setColor(Color.BLACK);
canvas.translate(20,0);
canvas.drawPath(path,paint);
Paint paint = getPaint();
Path path = getPath();
//第一條原生Path
canvas.drawPath(path,paint);
//第二條Path
canvas.translate(0,200);
paint.setPathEffect(new DiscretePathEffect(2,5));
canvas.drawPath(path,paint);
//第三條Path
canvas.translate(0,200);
paint.setPathEffect(new DiscretePathEffect(6,5));
canvas.drawPath(path,paint);
//第四條Path
canvas.translate(0,200);
paint.setPathEffect(new DiscretePathEffect(6,15));
canvas.drawPath(path,paint);
DiscretePathEffect離散路徑效應(yīng)
Paint paint = getPaint();
Path path = new Path();
//畫(huà)出原始路徑
path.moveTo(100,600);
path.lineTo(400,100);
path.lineTo(700,600);
canvas.drawPath(path,paint);
//構(gòu)建印章路徑
Path stampPath = new Path();
stampPath.moveTo(0,20);
stampPath.lineTo(10,0);
stampPath.lineTo(20,20);
stampPath.close();
stampPath.addCircle(0,0,3, Path.Direction.CCW);
//使用印章路徑效果
canvas.translate(0,100);
paint.setPathEffect(new PathDashPathEffect(stampPath,35,0, PathDashPathEffect.Style.TRANSLATE));
canvas.drawPath(path,paint);
//畫(huà)原始路徑
Paint paint = getPaint();
Path path = getPath();
canvas.drawPath(path,paint);
//僅應(yīng)用圓角特效的路徑
canvas.translate(0,200);
CornerPathEffect cornerPathEffect = new CornerPathEffect(100);
paint.setPathEffect(cornerPathEffect);
canvas.drawPath(path,paint);
//僅應(yīng)用虛線特效的路徑
canvas.translate(0,200);
DashPathEffect dashPathEffect = new DashPathEffect(new float[]{2,5,10,10},0);
paint.setPathEffect(dashPathEffect);
canvas.drawPath(path,paint);
//利用ComposePathEffect先應(yīng)用圓角特效,再應(yīng)用虛線特效
canvas.translate(0,200);
ComposePathEffect composePathEffect = new ComposePathEffect(dashPathEffect,cornerPathEffect);
paint.setPathEffect(composePathEffect);
canvas.drawPath(path,paint);
//利用SumPathEffect,分別將圓角特效應(yīng)用于原始路徑,然后將生成的兩條特效路徑合并
canvas.translate(0,200);
paint.setStyle(Paint.Style.STROKE);
SumPathEffect sumPathEffect = new SumPathEffect(cornerPathEffect,dashPathEffect);
paint.setPathEffect(sumPathEffect);
canvas.drawPath(path,paint);
ComposePathEffect和SumPathEffect
3.字體相關(guān)
方法 |
名稱 |
取值說(shuō)明 |
setTextSize(float textSize) |
文字大小 |
float |
setFakeBoldText(boolean fakeBoldText) |
粗體文字 |
boolean |
setStrikeThruText(boolean strikeThruText) |
刪除線 |
boolean |
setUnderlineText(boolean underlineText) |
下劃線 |
boolean |
setTextAlign(Paint.Align align) |
文字基線位置 |
Align.LEFT ,Align.CENTER ,Align.RIGHT ,這里的位置是說(shuō)的繪制起點(diǎn)x,y相對(duì)于文字的位置,而不是要繪制的文字對(duì)應(yīng)起點(diǎn)x,y的位置 |
setTextScaleX(float scaleX) |
水平拉伸 |
float |
setTextSkewX(float skewX) |
水平傾斜度 |
float |
setTypeface(Typeface typeface) |
字體樣式 |
android.graphics.Typeface |
setLinearText(boolean linearText) |
文本線性緩存 |
boolean 開(kāi)啟后會(huì)影響顯示速度 |
setSubpixelText(boolean subpixelText) |
亞像素 |
可以增加字體清晰度,實(shí)測(cè)效果無(wú)明顯變化 |
4.圖像處理和measure測(cè)量相關(guān)