2

I need to draw this:

result

and this: enter image description here

Can i make object and rotate it from point with x y cord and length + angle (vector)?

But i can't understand how to make a clip mask for canvas using Path.

red.setColor(0xff033cd0);
        red.setStyle(Paint.Style.FILL);
        path.reset();
        path = new Path();
        path.reset();
        path.moveTo(boxWTstopX, boxWTstartY);
        path.lineTo(boxWTstartX, boxWTstartY);
       // path.moveTo(point2_returned.x, point2_returned.y);
        path.lineTo(boxWTstartX, boxWTstopY);
        path.lineTo(boxWTstopX, boxWTstartY);
        //path.moveTo(point3_returned.x, point3_returned.y);
       // path.lineTo(point1_returned.x, point1_returned.y);
        path.close();

        //canvas.drawPath(path, red);
        canvas.clipPath(path);

But after that i drawing on Retrangle region... How i do that? i have no idea.

P.S:

I have no idea why i cant make object retrangle with lenght 100 and width 200 and than print it from cords! It will be more "friendly" than 2 points... is it posible?

Maybe there is a way to make object (contains: paths + rects + etc) and than print it from x y cords?

fadden
  • 51,356
  • 5
  • 116
  • 166
Dmitry Lyalin
  • 341
  • 6
  • 15

1 Answers1

0

Can i make object and rotate it from point with x y cord and length + angle (vector)?

Well, you can. But instead of rotating the object, you could rotate the canvas in increments and then draw. So what you need to do is use canvas.rotate(). Your requirement sounds a lot like the drawing the pointers of Meter guage that I worked on. You can refer this: https://stackoverflow.com/a/33606134/4747587. This will give you an idea on how to draw by rotating the canvas.

But i can't understand how to make a clip mask for canvas using Path.

You use clipPath to perform a sort of Masking. How you do that? Well refer to this: How to Clip a Star in android ? But the appearance of the star is clear. The code in the question will let you know how to use clipPath. But you can't get ANTI-ALIAS in this. If you want that, go through the answer to perform Bitmap Masking.

Community
  • 1
  • 1
Henry
  • 17,490
  • 7
  • 63
  • 98
  • Thak you ill try this! \0/ – Dmitry Lyalin Nov 20 '15 at 15:29
  • Now i have an arc, and use it like progress bar. But there are one problem... When val is rising by 1, it grows 1 degree.. it's a very big step. How i can move it slowly by 1/2 of degree or 1/4? – Dmitry Lyalin Dec 04 '15 at 15:10
  • `Canvas.rotate(float degree, float x, float y)` : So you can increment the `degree` by 0.25 or 0.5 based on your need. That should work. – Henry Dec 05 '15 at 03:00
  • And there are no way to use float in DrawArc method? So when i try to add float degree1 = 123.02 studio show error that is double, not float.... so any way ill try both again. – Dmitry Lyalin Dec 05 '15 at 07:52
  • Yes by default `123.02` is considered `double`. Instead, use `float degree1 = 123.02f`. This is how you define floating number. – Henry Dec 06 '15 at 08:36