11.1绘制基本图形-面试例题2:绘制多个像素点和多条直线
2012-07-25 21:37
573 查看
使用drawPoints方法来绘制多个像素点 drawLines方法绘制多条直线,具体说明如下:
public void drawPoints(float[] pts, int offset, int count, Paint paint)
Since: API Level 1
Draw a series of points. Each point is centered at the coordinate specified by pts[], and its diameter is specified by the paint's stroke width (as transformed by the canvas' CTM), with special treatment for a stroke width of 0, which always draws exactly 1 pixel (or at most 4 if antialiasing is enabled). The shape of the point is controlled by the paint's Cap type. The shape is a square, unless the cap type is Round, in which case the shape is a circle.
Parameters
public void drawLines(float[] pts, int offset, int count, Paint paint)
Since: API Level 1
Draw a series of lines. Each line is taken from 4 consecutive values in the pts array. Thus to draw 1 line, the array must contain at least 4 values. This is logically the same as drawing the array as follows: drawLine(pts[0], pts[1], pts[2], pts[3]) followed by drawLine(pts[4], pts[5], pts[6], pts[7]) and so on.
Parameters
代码:
效果图:
![](http://blog.51cto.com/attachment/201207/213711658.jpg)
public void drawPoints(float[] pts, int offset, int count, Paint paint)
Since: API Level 1
Draw a series of points. Each point is centered at the coordinate specified by pts[], and its diameter is specified by the paint's stroke width (as transformed by the canvas' CTM), with special treatment for a stroke width of 0, which always draws exactly 1 pixel (or at most 4 if antialiasing is enabled). The shape of the point is controlled by the paint's Cap type. The shape is a square, unless the cap type is Round, in which case the shape is a circle.
Parameters
pts | Array of points to draw [x0 y0 x1 y1 x2 y2 ...] |
---|---|
offset | Number of values to skip before starting to draw. |
count | The number of values to process, after skipping offset of them. Since one point uses two values, the number of "points" that are drawn is really (count >> 1). |
paint | The paint used to draw the points |
Since: API Level 1
Draw a series of lines. Each line is taken from 4 consecutive values in the pts array. Thus to draw 1 line, the array must contain at least 4 values. This is logically the same as drawing the array as follows: drawLine(pts[0], pts[1], pts[2], pts[3]) followed by drawLine(pts[4], pts[5], pts[6], pts[7]) and so on.
Parameters
pts | Array of points to draw [x0 y0 x1 y1 x2 y2 ...] |
---|---|
offset | Number of values in the array to skip before drawing. |
count | The number of values in the array to process, after skipping "offset" of them. Since each line uses 4 values, the number of "lines" that are drawn is really (count >> 2). |
paint | The paint used to draw the points |
package com.app; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.view.View; public class DrawPointsView extends View{ public DrawPointsView(Context context) { super(context); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Paint paint = new Paint(); paint.setColor(Color.RED); canvas.drawPoints(new float[]{10,10,30,30,50,50}, 0, 6, paint); canvas.drawPoints(new float[]{10,100,30,150,50,200}, 2, 4, paint); canvas.drawLines(new float[]{10,230,50,260,80,300,130,350}, 0, 8, paint); } }
效果图:
![](http://blog.51cto.com/attachment/201207/213711658.jpg)
相关文章推荐
- 11.1绘制基本图形-面试例题3:绘制三角形
- php使用gd2绘制基本图形示例(直线、圆、正方形)
- html5绘制基本图形-直线
- Canvas入门(1):绘制矩形、圆、直线、曲线等基本图形
- Canvas入门(1):绘制矩形、圆、直线、曲线等基本图形
- 面试例题1:如何在android应用程序的窗口上绘制图形
- Canvas入门(1):绘制矩形、圆、直线、曲线等基本图形
- 【Unity Shader学习笔记】(三)绘制点、直线、网格等基本图形
- 游戏开发笔记之四——游戏画面绘图(一)基本图形绘制
- Quartz 2D介绍及基本图形绘制
- 学习OpenCV2——绘制基本图形及文字
- Direct2D (3) : 使用浮点参数绘制基本图形
- 利用QT来实现基本图形的绘制应用
- Android学习日记(yzy):opengl 绘制2d图形 基本框架
- Quartz2D 绘制基本图形
- html5 canvas基本图形绘制
- 【Visual C++】游戏开发笔记之四——游戏画面绘图(一)基本图形绘制
- 【OpenGL】学习笔记之一 绘制基本图形单元的方法
- 立体像素画:Obelisk.js绘制等轴透视立体图形(Isometric Graphics) 作者:Alex Young
- html5绘制基本图形-圆形