试图实现图像的徒手裁剪,所以我能够在图像上绘图。但它超出了位图区域。我只是想限制用户只能在位图区域内绘制,请查看下面的屏幕截图。
我正在尝试实现Photoshop 套索工具之类的功能。
它在视图区域之外绘制,这会产生不正确的输出。
输出
代码@
绘制
public void onDraw(Canvas canvas) {
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
canvas.drawBitmap(bitmap, rect, rect, null);
// RectF r = new RectF();
// Matrix matrix = new Matrix();
// matrix.mapRect(r);
// Log.i(TAG, "Rect " + r.left + " " + r.top + " " + r.right + " " +
// r.bottom + " ");
// canvas.clipRect(r.left, r.top, r.right, r.bottom);
Path path = new Path();
boolean first = true;
for (int i = 0; i < points.size(); i += 2) {
Point point = points.get(i);
if (first) {
first = false;
path.moveTo(point.x, point.y);
} else if (i < points.size() - 1) {
Point next = points.get(i + 1);
path.quadTo(point.x, point.y, next.x, next.y);
} else {
mlastpoint = points.get(i);
path.lineTo(point.x, point.y);
}
}
canvas.drawPath(path, paint);
}
onCrop
Bitmap resultingImage = Bitmap.createBitmap(widthOfscreen,heightOfScreen, bitmap1.getConfig());
Canvas canvas = new Canvas(resultingImage);
Paint paint = new Paint();
paint.setAntiAlias(true);
Path path = new Path();
for (int i = 0; i < SomeView.points.size(); i++) {
path.lineTo(SomeView.points.get(i).x, SomeView.points.get(i).y);
}
// path.lineTo(150, 0);
// path.lineTo(230, 120);
// path.lineTo(70, 120);
// path.lineTo(150, 0);
canvas.drawPath(path, paint);
if(crop){
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
}else{
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_OUT));
}
建议我实现我的目标。