我有带图像的图像视图。我单击图像(onTouchEvent)并获得坐标(x,y)的点并在点之间一一画线:
@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 to the 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 the list
for (int i = 0; i < 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 with next point (if it 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;
}
所以我得到了很多点,我必须在所有连接点的区域中切割图像区域。我需要指定区域(连接点区域)中的部分图像。
我如何获得点区域并在imageview中剪切该图像区域?