我想用多条路径裁剪图像,如下图所示:
到目前为止,我已经实现了将所有绘制的路径保存到ArrayList
,然后我在另一个活动中检索那些裁剪路径。
但是,每条路径都添加了第一个绘制点。
这是我的代码:
public boolean onTouch(View view, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
points.clear();
points2 = new ArrayList<Point>();
}
Point point = new Point();
point.x = (int) event.getX();
point.y = (int) event.getY();
zoomPos.x = event.getX();
zoomPos.y = event.getY();
if (flgPathDraw) {
zooming = true;
if (bfirstpoint) {
if (comparepoint(mfirstpoint, point)) {
points.add(mfirstpoint);
points2.add(mfirstpoint);
} else {
points.add(point);
points2.add(point);
}
} else {
points.add(point);
points2.add(point);
}
if (!(bfirstpoint)) {
mfirstpoint = point;
bfirstpoint = true;
}
}
invalidate();
if (event.getAction() == MotionEvent.ACTION_UP) {
mlastpoint = point;
if (flgPathDraw) {
if (points.size() > 12) {
if (!comparepoint(mfirstpoint, mlastpoint)) {
zooming = false;
points2.add(mfirstpoint);
addpaths.add(path);
invalidate();
}
}
}
if (points2!=null&&!(points2.isEmpty())) {
pointlists.add(points2);
}
}
return true;
}
//Croping code for drawn paths.
for (int j=0;j<CutPhotoView.pointlists.size();j++) {
for (int i = 0; i <CutPhotoView.pointlists.get(j).size(); i++) {
path.lineTo(CutPhotoView.pointlists.get(j).get(i).x,
CutPhotoView.pointlists.get(j).get(i).y);
}
canvas.drawPath(path, paint);
}
答案 0 :(得分:0)