java - Build area on image using many points -


i have imageview image. click on image (ontouchevent) , got points coordinates (x,y) , drawing line between points 1 one:

@override public boolean ontouchevent(motionevent event) {     int positionx = (int) event.getrawx();     int positiony = (int) event.getrawy() - 80;     switch (event.getaction() & motionevent.action_mask) {         case motionevent.action_down:             if (event.getaction() == motionevent.action_down) {                  // add current touch position list of points                 pointslist.add(new point(positionx, positiony));                 log.d(tag, " positionx: " + positionx + " positiony: " + positiony);                  bitmap = bitmap.copy(bitmap.config.argb_8888, true);                  canvas canvas = new canvas(bitmap);                 paint paint = new paint();                 paint.setcolor(color.red);                 paint.setstrokewidth(3);                  // iterate on list                 (int = 0; < pointslist.size(); i++) {                     point current = pointslist.get(i);                      // draw points                     canvas.drawcircle(current.x, current.y, 10, paint);                     log.d(tag, " startcurrentx: " + current.x + " startcurrenty: " + current.y);                      // draw line next point (if exists)                     if (i + 1 < pointslist.size()) {                         point next = pointslist.get(i + 1);                         canvas.drawline(current.x, current.y, next.x, next.y, paint);                         log.d(tag, " currentx: " + current.x + " currenty: " + current.y + " nextx: " + next.x + " nexty: " + next.y);                     }                 }             }              setimagebitmap(bitmap);             break;     }     return true; } 

so got many points , have cut image area in area of connected points. need part of image in specified area (area in connected points).

how can area in points , cut area of image in imageview?

this may :

create path points in list, , calculate lower , upper bounds of polygon represented them.

path polypath = new path(); int minx,miny,maxx,maxy;  for( point current : pointslist ){ polypath.lineto(current.x, current.y);  //to : add calculation minx,miny,maxx,maxy here //  } polypath.lineto(pointslist.get(0).x, pointslist.get(0).y); polypath.close(); 

then create cropped bitmap follows :

paint paint = new paint(); paint.setstyle(paint.style.fill); paint.setxfermode(new porterduffxfermode(mode.clear));  polypath.setfilltype(path.filltype.inverse_winding);  bitmap newbitmap = bitmap.createbitmap(bitmap, minx, miny, maxx-minx, maxy-miny); canvas canvas = new canvas(newbitmap);  canvas.drawpath(polypath, paint);    canvas.drawbitmap(newbitmap, 0, 0, paint); 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -