moveto, lineTo, quadto, cubicto, arcto in Android (example)
Source: Internet
Author: User
<span id="Label3"></p>1. Why<p><p>Recently in the writing of Android paint often use these <code>什么什么To</code> , at first I really do not know <code>cubicTo</code> 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.<br>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.</p></p>2, MoveTo<p><p><code>moveTo</code>does not draw and is used only to move the move Brush.<br>Use it in the following ways.</p></p>3, LineTo<p><p><code>lineTo</code>Used for line Drawing.</p></p><pre class="hljs"><pre class="hljs"><code>mPath.lineTo(300, 300);canvas.drawPath(mPath, mPaint);</code></pre></pre><p><p>The default is drawn starting at coordinates (0,0).</p></p><p><p></p></p><p><p>Did we not say that we <code>moveTo</code> used to move the brushes?</p></p><pre class="hljs"><pre class="hljs"><code>mPath.moveTo(100, 100);mPath.lineTo(300, 300);canvas.drawPath(mPath, mPaint);</code></pre></pre><p><p>Move the brush (100,100) at the beginning of the drawing, the effect</p></p><p><p></p></p>4, Quadto<p><p><code>quadTo</code>Used to draw a smooth curve, that is, a Bezier Curve.</p></p><p><p><code>mPath.quadTo(x1, y1, x2, y2)</code>(x1,y1) is the control point, (x2,y2) is the end Point.</p></p><p><p>In the same way, we need <code>moveTo</code> to help Control.</p></p><pre class="hljs"><pre class="hljs"><code>mPath.moveTo(100, 500);mPath.quadTo(300, 100, 600, 500);canvas.drawPath(mPath, mPaint);</code></pre></pre><p><p>Effect</p></p><p><p></p></p>5, Cubicto<p><p><code>cubicTo</code>The same is used to achieve Bezier Curves.</p></p><p><p><code>mPath.cubicTo(x1, y1, x2, y2, x3, y3)</code>(x1,y1) is the control point, (x2,y2) is the control point, (x3,y3) is the end Point.</p></p><p><p>so, <code>cubicTo</code> <code>quadTo</code> What's The difference?</p></p><p><p>This is what the authorities say:</p></p> <blockquote> <blockquote> <p>Same as cubicto, but the coordinates is considered relative to the current point in this Contour.</p> </blockquote> </blockquote><p><p>To be blunt, it is a control point.</p></p><p><p>Then we want to draw the same curve as the previous one, how should we write it?</p></p><pre class="hljs"><pre class="hljs"><code>mPath.moveTo(100, 500);mPath.cubicTo(100, 500, 300, 100, 600, 500);</code></pre></pre><p><p>Look at the Effect:</p></p><p><p></p></p><p><p>Same!</p></p><p><p>What if we don't add <code>moveTo</code> it?</p></p><p><p>(0,0) is the starting point, (100,500) and (300,100) the Bezier curve is drawn for the control points:</p></p><p><p></p></p>6, ArcTo<p><p><code>arcTo</code>Used to draw an arc (actually a part of a circle or ellipse).</p></p><p><p><code>mPath.arcTo(ovalRectF, startAngle, sweepAngle)</code>, the <code>ovalRectF</code> rectangle for the ellipse, the <code>startAngle</code> starting angle, and the <code>sweepAngle</code> end Angle.</p></p><pre class="hljs coffeescript"><pre class="hljs coffeescript"><code><span class="hljs-keyword">new RectF(<span class="hljs-number">10, <span class="hljs-number">10, <span class="hljs-number">600, <span class="hljs-number">600);mPath.arcTo(mRectF, <span class="hljs-number">0, <span class="hljs-number">90);canvas.drawPath(mPath, mPaint);</span></span></span></span></span></span></span></code></pre></pre><p><p>Because of the <code>new RectF(10, 10, 600, 600)</code> square and intercept <code>0 ~ 90 度</code> , the resulting curve is a one-fourth-circle arc.</p></p><p><p>Effect</p></p><p><p></p></p><p><p>moveto, lineTo, quadto, cubicto, arcto in Android (example)</p></p></span>
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