4

I am making a app like Drive axle for Auto crop selected Path () using Paint () and then i make a this screen..

Change Images

But my Problem is that my starting point start with 0 position TOP_LEFT_CORNER X AND Y AXIS

USING this x and y coordinates i make a this type of rectangle but i need this type of out put using this coordinates..

{"TOP_LEFT_X_AXIS":" 43", "TOP_LEFT_y_AXIS":" 278",

"TOP_RIGHT_X_AXIS":"532", "TOP_RIGHT_y_AXIS":" 300 "}}

"BOTTOM_RIGHT_X_AXIS":"510", "BOTTOM_RIGHT_y_AXIS":" 614",

"BOTTOM_LEFT_X_AXIS":" 45", "BOTTOM_LEFT_Y_AXIS":" 597",

Need this type of Out Put see this image..

Change images

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    path = new Path();

    path.lineTo(x1, y1);
    path.lineTo(x2, y2);
    path.lineTo(x3, y3);
    path.lineTo(x4, y4);
    canvas.drawPath(path, currentPaint);

}

Edit :- 1-1-2014

Now i make rectangle successfully now i want to crop that part of images and set on another image view any idea about this..

Edit :- 1-07-2014

Now i want to draw a circle at corner tell me if you have any idea..

Output

Roadies
  • 3,309
  • 2
  • 30
  • 46
  • Have you tried to draw a rectangle instead by using *drawRect(...)*? BTW how do you obtain the cordinates? Do you have a touch listener? – Kumiho Dec 28 '13 at 08:10
  • @Kumiho please see my line draw code – Roadies Dec 28 '13 at 09:12
  • Where do you got the coordinates (x1, y1, x2, ...) from especially x1 and y1? A quick and dirty solution may be setting x1=top_right_corner_X and y1=bottom_left_corner_Y but it's not what you really should do. – Kumiho Dec 28 '13 at 09:23
  • @Kumiho this data comes from webservices {"TOP_LEFT_X_AXIS":" 43", "TOP_LEFT_y_AXIS":" 278", "TOP_RIGHT_X_AXIS":"532", "TOP_RIGHT_y_AXIS":" 300 "}} "BOTTOM_RIGHT_X_AXIS":"510", "BOTTOM_RIGHT_y_AXIS":" 614", "BOTTOM_LEFT_X_AXIS":" 45", "BOTTOM_LEFT_Y_AXIS":" 597", – Roadies Dec 28 '13 at 09:27
  • I see. Try to call path.moveTo (x1,y1) before calling path.lineTo(...). I'm not familiar with path but you can check the doc http://developer.android.com/reference/android/graphics/Path.html . – Kumiho Dec 28 '13 at 09:32
  • @Kumiho you say i right this path.moveTo(x1, y1); and then i right path.lineTo(x1, y1); – Roadies Dec 28 '13 at 09:34
  • yes, that's right.Give it a try. – Kumiho Dec 28 '13 at 09:35
  • @Kumiho not working bro !!! – Roadies Dec 28 '13 at 09:46
  • Hmm. This is strange, because according to the documentation lineTo(x,y):"Adds a line from the last point to the specified point (x,y). If no moveTo() call has been made for this contour, the first point is automatically set to (0,0)." it should work.With moveTo(x,y) you can draw a new contour starting at the point passed to this method. – Kumiho Dec 28 '13 at 09:54
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/44048/discussion-between-roadies-and-kumiho) – Roadies Dec 28 '13 at 10:07
  • @Kumiho any idea for crop that part of images.. – Roadies Jan 01 '14 at 05:42
  • Maybe this link can help you: http://stackoverflow.com/questions/13285661/android-cut-a-circle-from-a-square-bitmap – Kumiho Jan 06 '14 at 10:28
  • How about splitting your questions? The first question has been answered correct. Then you have edited it asking an additional question which has been answered correct too. As far as I can see it's not possible to accept two answers for the same question and I suppose it's a bad pratice to edit a post after the question has been answered properly by adding new questions. – Kumiho Jan 12 '14 at 12:58

2 Answers2

4

Please try this.. hope it will work for you.

canvas.drawPath(path, currentPaint);
canvas.drawCircle(x1, y1, 8, currentPaint);
canvas.drawCircle(x2, y2, 8, currentPaint);
canvas.drawCircle(x3, y3, 8, currentPaint);
canvas.drawCircle(x4, y4, 8, currentPaint);

Using This code get output this...

Output

Roadies
  • 3,309
  • 2
  • 30
  • 46
hpAndro
  • 178
  • 10
2

try this:

@Override
protected void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   path = new Path();

   path.moveTo(x1, y1);        // this should set the start point right

   //path.lineTo(x1, y1);    <-- this line should be drawn at the end of course,sorry
   path.lineTo(x2, y2);
   path.lineTo(x3, y3);
   path.lineTo(x4, y4);
   path.lineTo(x1, y1); 
   canvas.drawPath(path, currentPaint);

}
Roadies
  • 3,309
  • 2
  • 30
  • 46
Kumiho
  • 121
  • 4