Canvas 画布 paint 画笔 Path 路径
Path代表任意多条直线连接而成的任意图形,当Canvas根据Path绘制时,它可以绘制出任意的形状

使用 Matrix 控制图像或组件变换步骤:
①获取 Matrix对象,该 Matrix对象既可创建,也可直接获取其他对象内封装的 Matrix;
②调用 Matrix的方法进行平移、旋转、缩放、倾斜等;
③将程序对 Matrix所做的变换应用到指定图像或组件。

colorMatrix : (4x5矩阵) 用于处理颜色
matrix (矩阵) : 处理图形(3x3)
Matrix matrix = new Matrix();
canvas.drawBitmap(bitmap, matrix, paint);
matrix.setTranslate(100, 1000);
canvas.drawBitmap(bitmap, matrix, paint);

matrix.preTranslate(100,100);
matrix.preRotate(20,100,100);
canvas.drawBitmap(bitmap, matrix, paint);

Android为Bitmap提供了内存回收方法:
void recycle():强制回收Bitmap对象。
用于判断Bitmap 对象是否被回收的方法:
boolean isRecycle();

BitmapFactory工具类:通过对资源文件的解析获取Bitmap对象
eg:decodeResource(Resource res,int id) decodeByteArray(byte[] data, int offset,int length) etc.

绘图应该继承View组件,并重写它的onDraw(Canvas canvas)方法

drawCircle:canvas.drawCircle(cx, cy, radius, paint);x、y代表坐标、radius是半径、paint是画笔,就是画图的颜色;
实心(paint.setStyle(Paint.Style.FILL)) 空心(paint.setStyle(Paint.Style.STROKE);
正方形 drawRect:canvas.drawRect(left, top, right, bottom, paint)
left:是矩形距离左边的X轴 top:是矩形距离上边的Y轴 right:是矩形距离右边的X轴 bottom:是矩形距离下边的Y轴
圆角矩形:drawRoundRect(RectF rect,float rx,float ry,Paint paint);
eg:RectF rectf=new RectF(40,20,80,40); canvas.drawRonudRect(rectf,6,6,paint);
左上角坐标(left,top)和右下角坐标(right,bottom)
RectF re = new Rect(left, top, right, bottom); 椭圆:canvas.drawOval(re,paint);
drawLine(float startX,float startY,float stopX,float stopY, paint);
绘制多条线:drawLine(float[] pts,Paint paint); eg:drawLine(new float[]{10,10,30,10,30,10,15,30,15,30,10,10},paint);
drawPoints(float x,float y,Paint paint)
drawText(String Text,float x,float y,Paint paint); 在画布的指定位置绘制文字
drawPosText(String text,float[] pos,Paint paint);使用该方法绘制字符串时,需要为每一个字符指定一个位置
text用于指定要绘制的文字,pos用于指定每一个字的位置,paint用于指定使用的画笔


设置画笔:
Paint paint=new Paint();//创建一个采用默认设置的画笔
paint.setAntiAlias(true);//使用抗锯齿的功能
paint.setColor(Color.RED);//设置颜色为红色
paint.setStrokeWidth(2);//笔触的宽度为2像素
paint.setStyle(Style.STROKE);//填充样式为描边(实心是Style.FILL)

使用SurfaceView实现动画 :
SurfaceView一般会与SurfaceHolder结合使用, SurfaceHolder用于向与之关联的SurfaceView上绘图,调用SurfaceView的getHolder()方法即可获取SurfaceView关联的 SurfaceHolder。 SurfaceHolder提供了如下方法来获取Canvas对象:
Canvas lockCanvas():锁定整个 SurfaceView对象,获取其上的Canvas。
Canvas lockCanvas(Rect dirty):锁定 SurfaceView上Rect划分的区域,获取其上的Canvas。
获取指定了SurfaceView上的Canvas之后,程序就可以调用Canvas绘图,绘图完成后通过如下方法来释放绘图,提交所绘制的图形:
unlockCanvasAndPost(canvas);
当调用SurfaceHolder的 unlockCanvasAndPost方法之后,该方法之前所绘制的图形还在缓冲中,下一次的lockCanvas()方法锁定的区域可能会“遮挡”它。