Android Paint 学习总结

来源:互联网 发布:明源售楼软件 编辑:程序博客网 时间:2024/06/08 16:20

抗锯齿

当线条或图片倾斜旋转或快速变化时,如果需要避免出现锯齿的效果
画笔的抗锯齿(用于线条)设置

paint.setAntiAlias(true) 

图片线条(通用)的抗锯齿需要另外设置:

canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));

设置画笔风格(Style.FILL)(Style.FILL_AND_STROKE)(Style.STROKE)分别为填充,填充加描边,描边风格。

paint.setStyle(Style.FILL

设置阴影
setShadowLayer (float radius, float dx, float dy, int color)
radius:模糊度。
dx:水平位移。
dy:垂直位移。
文字的阴影支持硬件加速,图形一般用软件加速。
canvas基本方法
直线
drawLine(float startX,float startY,float stopX,float stopY, Paint paint)可以用来绘制直线。
startX:开始点的X坐标
startY:开始点的Y坐标
stopX:结束点的X坐标
stopY:结束点的Y坐标

drawLines(float[] pts,Paint paint)drawLines(float[] pts,int offset,int count,Paint paint)

pts:绘制直线的端点数组,每条直线占用4个数据。

offset:跳过的数据个数,这些数据将不参与绘制过程。

count:实际参与绘制的数据个数。

paint:绘制直线所使用的画笔。

上述两个方法可以绘制多条直线,pts是x,y坐标的数组,值得注意的是如果这里的坐标是(x1,y1,x2,y2,x3,y3,x4,y4)那么绘制的直线将是点(x1,y1),(x2,y2)的连线以及(x3,y3),(x4,y4)的连线,总共两条连线。
所以绘制的是每两个点的连线,并不是所有点连接

单个点以及多个点
void drawPoint (float x, float y, Paint paint)
void drawPoints (float[] pts, Paint paint)
void drawPoints (float[] pts, int offset, int count, Paint paint)
矩形
void drawRect (float left, float top, float right, float bottom, Paint paint)
void drawRect (RectF rect, Paint paint)
void drawRect (Rect r, Paint paint)
圆角矩形
void drawRoundRect (RectF rect, float rx, float ry, Paint paint)
其中rx代表圆角椭圆的x半径,ry代表圆角矩形的y半径
圆形
void drawCircle (float cx, float cy, float radius, Paint paint)
椭圆
void drawOval (RectF oval, Paint paint)
圆弧
void drawArc (RectF oval, float startAngle, float sweepAngle, boolean useCenter, Paint paint)
startAngle:开始的角度
sweepAngle:圆弧扫过的角度
userCenter:是否绘制出圆弧的两条边

RectF rectF = new RectF(100, 500, 900, 900);
canvas.drawArc(rectF, 0, -60, false, mPaint);

-60代表圆弧从逆时针方向扫过。

0 0
原创粉丝点击