Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

imagefilter - Free crop the image android

I want to crop the image with multiple paths like the below image:

Screenshot.

So far, what I have implemented saves all drawn paths into an ArrayList, then I retrieve those cropped paths in another activity.

However, every path is adding the first drawn point.

Here's my code:

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);
}

drawn paths

got the output

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

By modifying this example you can do it.

  1. create a List<Bitmap>.
  2. call save(); at end of crop method.
  3. in save method, generate bitmap of im_crop_image_view and add it to list.
  4. after all crops, pass list to second activity.
  5. in second activity, use FrameLayout and add dynamic imageviews for every bitmap of list to FrameLayout.

It will surely work. I have used this method to generate animation of image and succeeded. I am saving all bitmaps as png in internal storage for later use.

Here is what i have done. I added every image after interval of 1 second because i need to animate it for my app. You can put every image without interval.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...