Common Methods for canvas and Painting: canvaspaint
:
Page code:
@ Override protected void onDraw (Canvas canvas) {super. onDraw (canvas); mPaint = new Paint (); mPaint. setColor (Color. BLACK); // set the paint brush color mPaint. setTextSize (14); // set the font size canvas. drawText (actionStr, 100,100, mPaint); // write mPaint. setStrokeWidth (10); // set the line width mPaint. setStyle (Paint. style. STROKE); // set the hollow canvas. drawCircle (200,250, 80, mPaint); // draw a circle mPaint. setAntiAlias (true); // removes the Sawtooth canvas. drawLine (100,150,300, 3 50, mPaint); // draw line canvas. drawRect (100,400,400,500, mPaint); // draw a rectangular canvas. save (); // save the canvas status mPaint. setStyle (Paint. style. FILL); // set the solid canvas. clipRect (new Rect (100,550,300,750); // crop a canvas in the rectangular area. drawColor (Color. LTGRAY); // set the canvas color canvas. drawCircle (150,600,100, mPaint); // The canvas is displayed in the cropping area. restore (); // restore the canvas status mPaint. setStyle (Paint. style. STROKE); // set the hollow RectF rectF = new RectF (100,800,400,900 );// Set a new rectangular canvas. drawRoundRect (rectF, 20, 20, mPaint); // draw an arc rectangle. The second parameter is the x radius, and the third parameter is the y radius canvas. drawPoint (400,200, mPaint); // draw a canvas. drawPoints (new float [] {400,220,420,220,440,220}, mPaint); // draw multiple points Bitmap bitmap = BitmapFactory. decodeResource (getResources (), R. drawable. smile); // instantiate a bitmap canvas. drawBitmap (bitmap, 500,150, mPaint); // draw the image Path path = new Path (); path. moveTo (400,300); // no painting, only use To move the paint brush, which is equivalent to the starting point. Path. lineTo (600,350); // lineTo is used to draw a straight line. Path. moveTo (400,310); // It is not drawn and is only used to move the paint brush, which is equivalent to the start point. Path. quadTo (650,400,400,600); // quadTo is used to draw a smooth curve, namely, the besell curve. MPath. quadTo (x1, y1, x2, y2) (x1, y1) is the control point, and (x2, y2) is the end point. Path. moveTo (400,610); // It is not drawn and is only used to move the paint brush, which is equivalent to the start point. Path. cubicTo (400,700,500,550,600,900); // cubicTo is also used to implement the besell curve. 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 (600,100 0); // It is not drawn and is only used to move the paint brush, which is equivalent to the start point. RectF mRectF = new RectF (400,900,600,110 0); path. arcTo (mRectF, 0,270); // arcTo is used to draw an arc (actually a canvas that captures a circle or an elliptical part. drawPath (path, mPaint); // draw the RectF rectF1 = new RectF (100,900,200,100 0); canvas. drawArc (rectF1, // the size of the rectangle used by the arc is 0, // The starting angle is 180, // The scanning angle is false, // whether the center mPaint is used ); // draw the text content mPaint according to the specified point. setTextSize (16); mPaint. setStrokeWidth (1); canvas. drawPosText ("Hello world", new float [] {20, 20, // the first letter is in the coordinates of 20, 20 30, 30, // The second letter is in the coordinates of 30, 30, 40, 40, 50, 50, 60, 60, 70, 70, 80, 60, 90, 50,100, 40,110, 30,120, 20}, mPaint); canvas. drawTextOnPath ("123456789", path, 50,-30, mPaint); // draw text content in the specified path}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.