Android ApiDemos示例解析(73):Graphics->Points
本例对应的例子为DrawPoints.java,介绍如何使用Canvas来绘制点。
Canvas 提供3个重载函数来绘制点(单个点或是一组点)
public void drawPoint(float x, float y, Paint paint)
public void drawPoints(float[] pts, Paint paint)
public void drawPoints(float[] pts, int offset, int count, Paint paint)
绘制点的中心由点的坐标给定,点的宽度由Paint的Stroke宽度指定(并受当前Canvas的Matrix影响)。stroke width为0比较特殊,点的宽度总为1个像素(打开Antialiasing支持时为4个像素)。
本例绘制一组点和由点连接的直线:
[java]
Paint paint = mPaint;
canvas.translate(10, 10);
canvas.drawColor(Color.WHITE);
paint.setColor(Color.RED);
paint.setStrokeWidth(0);
canvas.drawLines(mPts, paint);
paint.setColor(Color.BLUE);
paint.setStrokeWidth(3);
canvas.drawPoints(mPts, paint);
作者:mapdigit
补充:移动开发 , Android ,