I'm trying to make the bottom side semicircular, but it doesn't work.
An example of a figure in "main background"
main background
Make a Path object by issuing 4 individual draw commands (3 draw lines for the 3 straight sides, 1 drawArc for the bottom), then draw that path to the canvas
Related
I'm new to Android canvas. I'm cutting Canvas using .ClipPath(path). in the path I used lineTo() method to add all the lines. now I need to the rounded corners of all corners like Pic-2. How can I do that?
I have this code to draw the arrow tail line between 2 point but how should I draw curved line for arrow tail?
canvas.drawLine(pt1[X], pt1[Y], pt2[X], pt2[Y], paint);//draw line
I want to have something like this, whereby the arrow is dynamic
Depending on what shape you want for the curved line, you could perhaps use Canvas.drawArc(), but that is restricted to sections of an oval aligned with the screen axes.
For a more general approach, define your curved line as a Path and then use Canvas.drawPath() to render it to the canvas. A Path can be composed of an arbitrary number of straight line, quadratic curve, and cubic curve segments. (See the docs for how to construct the Path that you want.) For a solid arrow tail, you should set the paint's style to FILL when calling drawPath().
My app teaches how to write letters and I want to draw for example letter "A" programmatically.
I do not want to draw it pixel by pixel(it is so hard!)
What other ways to do that?
UPDATE:
I want to show how to write "A" not just showing A in the screen
Romain Guy recently wrote a blog post on how to do path tracing using paths. If you can construct paths yourself (or finding a method for creating correct paths for letters) you could use the information from his blog to do something.
http://www.curious-creature.org/2013/12/21/android-recipe-4-path-tracing/#more-1904
Good luck
if you are using Canvas, you can draw text on canvas using this:
canvas.drawText("A",marginFromLeft,MarginFromRight, paint);
also you can draw bitmap of A on canvas using this:
canvas.drawBitmap(bmp,marginLeft,marginTop, paint);
after drawing this,you can animate an other image like circle using animationSet:
anim One: animate circle moving from bottom left to top center of A
anim Two: animate circle moving from top center of A to bottom left Right
anim Three: animate circle moving from left-verticaly-center to right-verticaly-center.
I am trying to draw smooth line following my finger. The problem is in superposition. Left example is array of drawLine, and right is drawPath. Is it way to make it like smooth left example?
Construct the line as a solid color, then wrap that line inside of a drawable. Turn this drawable transparent, and then draw it to the screen.
I am drawing an arc with a border by painting two arcs, one over the other the first being slightly larger.
The issue is with "slightly larger" this can end up with the border not always being even all the way round.
Both the arcs I am drawing have the same radius, I simply make it larger by adding a degree to the start and two degrees to the end (necessary to ensure the borders on either end of the arc are equal) and increasing the stroke width.
In the supplied picture the thicker border edge is the smallest I can possibly make it while it is still visible. (-1 degree off the inner arc)
I have considered drawing the arc outline with four separate calls two straight lines for either end and two arcs. This seems quite inefficient for what I want to achieve.
I am wondering if anyone has any suggestions about how else I could draw a border thats even, minimizing the number of draw/canvas rotation calls if possible.
Relevant code sample for current solution:
Paint mOutlinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
Paint mFillPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mFillPaint.setStyle(Style.STROKE);
mFillPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
mFillPaint.setColor(Color.TRANSPARENT);
mFillPaint.setStrokeWidth(mValueWidth);
mOutlinePaint.setStyle(Style.STROKE);
mOutlinePaint.setStrokeWidth(mBorderWidth);
mOutlinePaint.setColor(Color.WHITE);
mRect.set(mHalfXSubRadius, mHalfYSubRadius, mHalfXAddRadius, mHalfYAddRadius);
canvas.drawArc(mRect, ARC_START-1, MAX_ARC+2, false, mOutlinePaint);
canvas.drawArc(mRect, ARC_START, MAX_ARC, false, mFillPaint);
U shouldnt make your arc bigger, instead try to draw the same sized arc (in white), X pixel right,down,up,left,corners as well (total of 8 drawings).
where X is the border size u want.
after that draw the main arc (in gray) in the middle.
psuedo code:
paint=white;
drawArc(x,y+2);
drawArc(x,y-2);
drawArc(x+2,y+2);
drawArc(x+2,y-2);
drawArc(x-2,y+2);
drawArc(x-2,y+2);
drawArc(x+2,y);
drawArc(x-2,y);
paint=gray;
drawArc(x,y);