国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android中Paint類和Canvas類的方法匯總

2019-12-12 03:46:46
字體:
供稿:網(wǎng)友

Paint類的常用的方法

1.setColor方法,用于設(shè)置畫筆的顏色,

public void setColor(int color)//參數(shù)color為顏色值,也可以使用Color類定義的顏色

Color.BLACK:黑色

Color.BLUE:藍(lán)色

Color.CYAN:青綠色

Color.DKGRAY:灰黑色

Color.YELLOW:黃色

Color.GRAY:灰色

Color.GREEN:綠色

Color.LTGRAY:淺綠色

Color.MAGENTA:紅紫色

Color.TRANSPARENT:透明色

2.setAlpha方法,用于設(shè)置畫筆的透明度

public void setAlpha(int a )//參數(shù)a為透明度,其取值范圍為0~255,數(shù)值越小越透明

3.setStyle方法,用于設(shè)置畫筆的風(fēng)格,可以指定是圓心還是實(shí)心,該方法在矩形,圓形有明顯的效果

public void setStyle(Paint.Style style)//參數(shù)style為畫筆的風(fēng)格

Style.FILL:實(shí)心

Style.FILL_AND_STROKE:同時(shí)顯示實(shí)心和空心

Style.STROKE:空心

4.setStrokeWidth方法,用于設(shè)置畫筆的空心線寬,該方法在矩形,圓形,等圖形上有明顯的效果

public void setStrokeWidth(float width)//參數(shù)width為線寬,浮點(diǎn)型數(shù)據(jù)

5.setTextSize方法,用于設(shè)置畫筆的字體大小,主要用于繪制字符串

public void setTextSize(float textSize)//

6.setTypeface方法用于設(shè)置畫筆的字體樣式,可以使用系統(tǒng)自帶的字段,也可以使用自定義的字體

public void Typeface(Typeface typeface)//typeface為字體樣式

Typeface.DEFAULT:默認(rèn)字體

Typeface.DEFAULT_BOLD:加粗字體

Typeface.MONOSPACE:monospace字體

Typeface.SANS_SERIF:sans字體

Typeface.SERIF:serif字體

7.setTextScaleX方法.用于設(shè)置畫筆字體的比例因子,默認(rèn)為1,當(dāng)大于1時(shí)表示橫向拉伸,小于1時(shí)表示橫向壓縮

public void setTextScaleX(float scaleX)

8.setARGB方法,用于設(shè)置畫筆的顏色和透明度

public void setARGB(int a,int r,int g,int b);

參數(shù)a為透明度,范圍0~255

參數(shù)r為紅色的顏色值,范圍0~255

參數(shù)g為綠色的顏色值,范圍0~255

參數(shù)b為藍(lán)色的顏色值,范圍0~255

9.setUnderlineText方法,用于設(shè)置畫筆的下劃線

public void setUnderlineText(Boolean underlintext)

當(dāng)取值為true時(shí),表示顯示下劃線

10.setTextSkewX方法,用于設(shè)置畫筆的傾斜因子

public void setTextSkewX(float skewX)

參數(shù)skewX為傾斜因子,正數(shù)表示向左傾斜,負(fù)數(shù)表示向右傾斜

Canvas類的方法

1.public void drawColor(int color)

用于設(shè)置畫布的背景顏色

2.public void drawLine(float starX,float startY,float stopX,float stopY,Paint paint);

用于在畫布上繪制直線

參數(shù)分別為直線起點(diǎn)的X坐標(biāo),Y坐標(biāo),終點(diǎn)的X坐標(biāo),Y坐標(biāo),用到的畫筆

3.public void drawLines(float[] pts,Paint paint)

用于在畫布上繪制多條直線

參數(shù)pts為繪制直線的端點(diǎn)數(shù)組,每條直線占用4個(gè)數(shù)據(jù)

4.public void drawPoint(float x,float y,Paint paint)

用于在畫布上繪制點(diǎn)

參數(shù)為點(diǎn)的X,Y坐標(biāo),和所用的畫筆

5.public void drawPoints(float[] pts,Paint paint)

public void drawPoints(float[] pts,int offset,int count,Paint paint)

參數(shù)pts為繪制點(diǎn)的數(shù)組,每個(gè)點(diǎn)占用2個(gè)數(shù)據(jù)

參數(shù)offset為跳過的數(shù)據(jù)的個(gè)數(shù)

參數(shù)count為實(shí)際參與繪制的數(shù)據(jù)的個(gè)數(shù)

6.public void drawRect(Rect rect,Paint paint)

public void drawRect(RectF rect,Paint paint)

public void drawRect(float left,float float top,float right,float below,Paint paint)

用于繪制矩形

7.public void drawRoundRect(RectF rect,float rx,float ry,Paint paint)

用于繪制圓角矩形

rx為X方向上的圓角半徑

ry為Y方向上的圓角半徑

8.public void drawCircla(float cx,float cy,float radius, Paint paint)

用于在畫布上繪制圓形

cx為圓形的x坐標(biāo)

cy為圓形的y坐標(biāo)

rad為圓的的半徑

9.public void drawOval(RectF rect.Paint paint)

用于繪制橢圓

通過指定橢圓的外切矩形實(shí)現(xiàn)

10.public void drawPath(Path path,Paint paint)

用于在畫布上繪制任意多邊形來實(shí)現(xiàn)

11.public void drawArc(RectF oval,float startAngle,float sweepAngle,`Boolean usecenter,Paint p)

參數(shù)oval為圓弧所在的橢圓對(duì)象

startAngle為圓弧的起始角度,

sweepAngle為圓弧的角度,

useCenter表示是否顯示半徑連線,當(dāng)取值為true時(shí),顯示圓弧與圓心的半徑連線,

12,public void drawText(String text,float x,float y, Paint paint)

public void drawText(char[] text,int index,int count,float x,float y,Paint paint)
public void drawText(CharSequence text,int start,int end,float x,float y,Paint paint)
public void drawText(String text,int start,int end,float x,float y,Paint paint)

參數(shù)text為字符串的內(nèi)容,

x為X坐標(biāo)

y為Y坐標(biāo)

index為顯示的起始字符位置

count為顯示的字符個(gè)數(shù)

start為顯示的起始字符的位置

end為顯示的終止的字符的位置

13,public void drawBitmap(Bitmap bitmap,float left,float top,Paint paint)

參數(shù)bitmap為Bitmap對(duì)象,代表圖像資源,

left為圖像顯示的左邊的位置

right為圖像的顯示的右邊的位置

14,public int save()

用于鎖定畫布中的某一個(gè)或某幾個(gè)對(duì)象,用于鎖定對(duì)象操作的場(chǎng)合

使用sava方法鎖定畫布并完成操作之后,需要使用restore方法解除鎖定

15,public Boolean clipRect(Rect rect)

public Boolean clipRect(float left,float top,float right,float bottom)

public Boolean clipRect(int left,int top,int right,int boottom)

該方法用于裁剪畫布,設(shè)置畫布的顯示區(qū)域

16,public void rotate(float degrees)

public void rotate(float degrees,float px,float py)

用于旋轉(zhuǎn)畫布,通過旋轉(zhuǎn)畫布,可以將畫布上繪制的對(duì)象旋轉(zhuǎn)

參數(shù)degrees為旋轉(zhuǎn)的角度,正數(shù)為順時(shí)針方向,負(fù)數(shù)為逆時(shí)針方向

px為旋轉(zhuǎn)點(diǎn)的x坐標(biāo)

py為旋轉(zhuǎn)點(diǎn)的y坐標(biāo)

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持武林網(wǎng)!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 嫩江县| 攀枝花市| 延安市| 平乐县| 芒康县| 咸宁市| 阜宁县| 东乡| 齐齐哈尔市| 莱芜市| 嵩明县| 鄂伦春自治旗| 丰宁| 榆林市| 大渡口区| 宜城市| 北票市| 哈巴河县| 阿瓦提县| 麦盖提县| 平阳县| 锦屏县| 呼和浩特市| 临江市| 广丰县| 盐边县| 夹江县| 宣汉县| 神池县| 白山市| 明星| 惠水县| 安化县| 南昌市| 苍南县| 泊头市| 成安县| 改则县| 永吉县| 星子县| 莱州市|