安卓中Paint类和Canvas类的方法汇总_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > 安卓中Paint类和Canvas类的方法汇总

安卓中Paint类和Canvas类的方法汇总

 2017/2/9 5:32:19  方正小司马  程序员俱乐部  我要评论(0)
  • 摘要:Paint类的常用的方法1.setColor方法,用于设置画笔的颜色,publicvoidsetColor(intcolor)//参数color为颜色值,也可以使用Color类定义的颜色Color.BLACK:黑色Color.BLUE:蓝色Color.CYAN:青绿色Color.DKGRAY:灰黑色Color.YELLOW:黄色Color.GRAY:灰色Color.GREEN:绿色Color.LTGRAY:浅绿色Color.MAGENTA:红紫色Color.TRANSPARENT:透明色2
  • 标签:方法 can

Paint类的常用的方法


1.setColor方法,用于设置画笔的颜色,
public void setColor(int color)//参数color为颜色值,也可以使用Color类定义的颜色
Color.BLACK:黑色
Color.BLUE:蓝色
Color.CYAN:青绿色
Color.DKGRAY:灰黑色
Color.YELLOW:黄色
Color.GRAY:灰色
Color.GREEN:绿色
Color.LTGRAY:浅绿色
Color.MAGENTA:红紫色
Color.TRANSPARENT:透明色


2.setAlpha方法,用于设置画笔的透明度
public void setAlpha(int a )//参数a为透明度,其取值范围为0~255,数值越小越透明


3.setStyle方法,用于设置画笔的风格,可以指定是圆心还是实心,该方法在矩形,圆形有明显的效果
public void setStyle(Paint.Style style)//参数style为画笔的风格
Style.FILL:实心
Style.FILL_AND_STROKE:同时显示实心和空心
Style.STROKE:空心


4.setStrokeWidth方法,用于设置画笔的空心线宽,该方法在矩形,圆形,等图形上有明显的效果
public void setStrokeWidth(float width)//参数width为线宽,浮点型数据


5.setTextSize方法,用于设置画笔的字体大小,主要用于绘制字符串
public void setTextSize(float textSize)//


6.setTypeface方法用于设置画笔的字体样式,可以使用系统自带的字段,也可以使用自定义的字体
public void Typeface(Typeface typeface)//typeface为字体样式
Typeface.DEFAULT:默认字体
Typeface.DEFAULT_BOLD:加粗字体
Typeface.MONOSPACE:monospace字体
Typeface.SANS_SERIF:sans字体
Typeface.SERIF:serif字体


7.setTextScaleX方法.用于设置画笔字体的比例因子,默认为1,当大于1时表示横向拉伸,小于1时表示横向压缩
public void setTextScaleX(float scaleX)


8.setARGB方法,用于设置画笔的颜色和透明度
public void setARGB(int a,int r,int g,int b);
参数a为透明度,范围0~255
参数r为红色的颜色值,范围0~255
参数g为绿色的颜色值,范围0~255
参数b为蓝色的颜色值,范围0~255


9.setUnderlineText方法,用于设置画笔的下划线
public void setUnderlineText(Boolean underlintext)
当取值为true时,表示显示下划线


10.setTextSkewX方法,用于设置画笔的倾斜因子
public void setTextSkewX(float skewX)
参数skewX为倾斜因子,正数表示向左倾斜,负数表示向右倾斜

 


Canvas类的方法


1.public void drawColor(int color)
用于设置画布的背景颜色


2.public void drawLine(float starX,float startY,float stopX,float stopY,Paint paint);
用于在画布上绘制直线
参数分别为直线起点的X坐标,Y坐标,终点的X坐标,Y坐标,用到的画笔


3.public void drawLines(float[] pts,Paint paint)
用于在画布上绘制多条直线
参数pts为绘制直线的端点数组,每条直线占用4个数据


4.public void drawPoint(float x,float y,Paint paint)
用于在画布上绘制点
参数为点的X,Y坐标,和所用的画笔


5.public void drawPoints(float[] pts,Paint paint)
public void drawPoints(float[] pts,int offset,int count,Paint paint)
参数pts为绘制点的数组,每个点占用2个数据
参数offset为跳过的数据的个数
参数count为实际参与绘制的数据的个数


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坐标
cy为圆形的y坐标
rad为圆的的半径


9.public void drawOval(RectF rect.Paint paint)
用于绘制椭圆
通过指定椭圆的外切矩形实现


10.public void drawPath(Path path,Paint paint)
用于在画布上绘制任意多边形来实现


11.public void drawArc(RectF oval,float startAngle,float sweepAngle,`Boolean usecenter,Paint p)
参数oval为圆弧所在的椭圆对象
startAngle为圆弧的起始角度,
sweepAngle为圆弧的角度,
useCenter表示是否显示半径连线,当取值为true时,显示圆弧与圆心的半径连线,


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)
参数text为字符串的内容,
x为X坐标
y为Y坐标
index为显示的起始字符位置
count为显示的字符个数
start为显示的起始字符的位置
end为显示的终止的字符的位置


13,public void drawBitmap(Bitmap bitmap,float left,float top,Paint paint)
参数bitmap为Bitmap对象,代表图像资源,
left为图像显示的左边的位置
right为图像的显示的右边的位置


14,public int save()
用于锁定画布中的某一个或某几个对象,用于锁定对象操作的场合
使用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)
该方法用于裁剪画布,设置画布的显示区域


16,public void rotate(float degrees)
public void rotate(float degrees,float px,float py)
用于旋转画布,通过旋转画布,可以将画布上绘制的对象旋转
参数degrees为旋转的角度,正数为顺时针方向,负数为逆时针方向
px为旋转点的x坐标
py为旋转点的y坐标

发表评论
用户名: 匿名