MoveTo, LineTo, Quadto, Cubicto, ArcTo in Android (example)

Source: Internet
Author: User

Recently in the writing of Android paint often use these 什么什么To , at first I really do not know cubicTo this method, let alone can not tell them, so to make a small note, record the role of MoveTo, LineTo, Quadto, Cubicto, ArcTo, Often used when customizing the view.
Next, we'll share some of the things we wrote these days. I believe that for beginners will be a little help, Master also help to see there is right, welcome to spit Groove.

2, MoveTo

moveTodoes not draw and is used only to move the move brush.
Use it in the following ways.

3, LineTo

lineToUsed for line drawing.

Mpath.lineto (+); Canvas.drawpath (MPath, mpaint);

The default is drawn starting at coordinates (0,0).

Did we not say that we moveTo used to move the brushes?

Mpath.moveto (Mpath.lineto); Canvas.drawpath (MPath, mpaint);

Move the Brush (100,100) at the beginning of the drawing, the effect

4, Quadto

quadToUsed to draw a smooth curve, that is, a Bezier curve.

mPath.quadTo(x1, y1, x2, y2)(X1,Y1) is the control point, (X2,y2) is the end point.

In the same way, we need moveTo to help control.

Mpath.moveto (Mpath.quadto), Canvas.drawpath (MPath, Mpaint), (+);

Effect

5, Cubicto

cubicToThe same is 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.

So, cubicTo quadTo What's the difference?

This is what the authorities say:

Same as Cubicto, but the coordinates is considered relative to the current point in this contour.

To be blunt, it is a control point.

Then we want to draw the same curve as the previous one, how should we write it?

Mpath.moveto (+), Mpath.cubicto (100, 500, 300, 100, 600, 500);

Look at the effect:

Same!

What if we don't add moveTo it?

(0,0) is the starting point, (100,500) and (300,100) the Bezier curve is drawn for the control points:

6, ArcTo

arcToUsed to draw an arc (actually a part of a circle or ellipse).

mPath.arcTo(ovalRectF, startAngle, sweepAngle), the ovalRectF rectangle for the ellipse, the startAngle starting angle, and the sweepAngle end angle.

MRECTF = new RECTF (ten, ten, +), Mpath.arcto (MRECTF, 0, N); Canvas.drawpath (MPath, mpaint);

Because of the new RectF(10, 10, 600, 600) square and intercept 0 ~ 90 度 , the resulting curve is a one-fourth-circle arc.

Effect


MoveTo, LineTo, Quadto, Cubicto, ArcTo in Android (example)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.