:
page code:
@Overrideprotected void OnDraw (CanvasCanvas) {Super.ondraw (Canvas); Mpaint = new Paint (); Mpaint.setcolor (Color.Black);//Set Brush colorMpaint.settextsize ( -);//Set Font size Canvas. DrawText (Actionstr, -, -, Mpaint);//writeMpaint.setstrokewidth (Ten);//Set line widthMpaint.setstyle (Paint.Style.STROKE);//Set Hollow Canvas. Drawcircle ( $, -, the, Mpaint);//Draw a circleMpaint.setantialias (TRUE);//anti-aliasing Canvas. DrawLine ( -, Max, -, -, Mpaint);//Draw line Canvas. DrawRect ( -, -, -, -, Mpaint);//Draw Rectangle Canvas. Save ();//Save Canvas StateMpaint.setstyle (Paint.Style.FILL);//Set solid Canvas. ClipRect (New Rect ( -,550, -, -));//Cut out a rectangular area Canvas. Drawcolor (Color.ltgray);//Set canvas color Canvas. Drawcircle ( Max, -, -, Mpaint);//within the cropping area, can display Canvas. Restore ();//restore Canvas StateMpaint.setstyle (Paint.Style.STROKE);//Set HollowRECTF RECTF = new RECTF ( -, -, -, the);//Set a new rectangle Canvas. Drawroundrect (RECTF, -, -, Mpaint);//Draw the arc rectangle, the second parameter is the x radius, the third parameter is the y radius Canvas. Drawpoint ( -, $, Mpaint);//Draw a dot Canvas. drawpoints (Newfloat[]{ -, -,420, -, the, -}, Mpaint);//Draw multiple pointsBitmap Bitmap = Bitmapfactory.decoderesource (Getresources (), r.drawable.smile);//instantiation of a bitmap Canvas. Drawbitmap (Bitmap, -, Max, Mpaint);//Painting picturesPath PATH = new Path (); Path.moveto ( -, -);//will not be drawn, only for moving the move brush, equivalent to the starting point. Path.lineto ( -, -);//lineto is used for line drawing. Path.moveto ( -,310);//will not be drawn, only for moving the move brush, equivalent to the starting point. Path.quadto (650, -, -, -);The//quadto is used to draw a smooth curve, the Bezier curve. Mpath.quadto (x1, y1, x2, y2) (x1,y1) is the control point, (X2,y2) is the end point. Path.moveto ( -,610);//will not be drawn, only for moving the move brush, equivalent to the starting point. Path.cubicto ( -, the, -,550, -, the);The//cubicto is also used to achieve Bezier curves. Mpath.cubicto (x1, y1, x2, y2, X3, y3) (X1,Y1) is the control point, (X2,y2) is the control point, (X3,Y3) is the end point. Path.moveto ( -, +);//will not be drawn, only for moving the move brush, equivalent to the starting point. RECTF MRECTF = new RECTF ( -, the, -,1100); Path.arcto (MRECTF,0, the);//arcto is used to draw arcs (actually part of a circle or ellipse Canvas. DrawPath (path, mpaint);//Draw a curveRECTF rectF1 = new RECTF ( -, the, $, +);Canvas. DrawArc (RectF1,the size of the rectangular area used by the//ARC 0,//Start angle the,//Sweep angleFalse//Whether to use the centerMpaint);//Draw text content according to established pointsMpaint.settextsize ( -); Mpaint.setstrokewidth (1);Canvas. Drawpostext ("Hello World", newfloat[]{ -, -,//first letter in coordinates 20,20 -, -,//second letter in coordinate 30,30 +, +, -, -, -, -, -, -, the, -, -, -, -, +, the, -, -, -}, Mpaint);Canvas. Drawtextonpath ("123456789", Path, -, - -, Mpaint);//Draw text content according to established path}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Common methods for canvas and paint