Canvas,paint
1. In the Android drawing but often use the canvas and the paint class, canvas is like a canvas, the above already have you want to draw the outline of the picture, and paint is like a brush, you need to give the canvas Tim color and other operations.
These two classes are usually used in the OnDraw (Canvas canvas) method.
2.Bitmap: Represents a bitmap, the bitmapdrawable package mutation is a Bitmao object
There are some examples of 3.Canvas inside:
DrawArc (parametric) drawing arcs
Drawbitmao (Bitmap Bitmap, Rect rect,rect dst,paint paint) Draws a piece of "dug" from the source map at the specified point
ClipRect (float left,float top,float right,float bottom) cuts a rectangular area
Clipregion (region) cuts a specified area.
In addition to drawing a basic graphic directly, canvas provides the following methods for coordinate changes:
Rotate (float degree,float px, float py): Perform rotation changes on canvas
Scale (float sx,float sy,float px,float py): Zoom transform to Cnavas
Skew (float sx,float sy): Tilt transform on canvas
Translate (float dx,float dy): Perform movement on Cnavas
The 4.Paint class is primarily used to set drawing styles including brush color, brush thickness, fill style, etc.
Paint provides a number of ways
Setargb (int a,int r,int g,int b)/setcolor (int color): Set color
And some other methods
5. Below is an example of these two classes:
1 Public classMyViewextendsView {2 3 PublicMyView (Context context) {4 Super(context);5 //TODO auto-generated Constructor stub6 }7 8 PublicMyView (Context context, AttributeSet attrs) {9 Super(context, attrs);Ten //TODO auto-generated Constructor stub One } A - PublicMyView (context context, AttributeSet attrs,intDefstyle) { - Super(context, attrs, defstyle); the //TODO auto-generated Constructor stub - } - - //Override this method to make a drawing + @Override - protected voidOnDraw (canvas canvas) { + Super. OnDraw (canvas); A //Paint the whole canvas white at Canvas.drawcolor (color.white); -Paint paint =NewPaint (); - //de-aliasing -Paint.setantialias (true); - Paint.setcolor (color.blue); - Paint.setstyle (style.stroke); inPaint.setstrokewidth (3); - //Draw a graphic toCanvas.drawcircle (40, 40, 30, paint); + //draw a square shape -Canvas.drawrect (10, 80, 70, 140, paint); the //Draw a rectangle *Canvas.drawrect (10, 150, 70, 190, paint); $RECTF rel =NewRECTF (10, 200, 70, 230);Panax Notoginseng //Draw rounded rectangles -Canvas.drawroundrect (rel, 15, 15, paint); theRECTF Rell =NewRECTF (10, 240, 70, 270); + //Draw Ellipse A Canvas.drawoval (Rell, paint); the //defines a path object, enclosing it as a triangle +Path path1 =NewPath (); -Path1.moveto (10, 340); $Path1.lineto (70, 340); $Path1.lineto (40, 290); - path1.close (); - the } - Wuyi}