免费裁剪图像android [英] Free crop the image android

查看:102
本文介绍了免费裁剪图像android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用多条路径裁剪图像,如下图所示:

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

.

到目前为止,我已经实现的方法将所有绘制的路径保存到ArrayList中,然后在另一个活动中检索这些裁剪的路径.

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.

这是我的代码:

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

推荐答案

通过修改您可以做到的例子.

By modifying this example you can do it.

  1. 创建一个List<Bitmap>.
  2. 在裁剪方法结束时调用save();.
  3. 在保存方法中,生成im_crop_image_view的位图并将其添加到列表中.
  4. 所有庄稼之后,将清单传递给第二项活动.
  5. 在第二个活动中,使用FrameLayout并为列表的每个位图将动态图像视图添加到FrameLayout.
  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.

它肯定会工作.我已经使用这种方法来生成图像动画并成功. 我正在将所有位图另存为png,以供以后使用.

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.

这里是我所做的.我在1秒间隔后添加了每张图像,因为我需要为我的应用制作动画.您可以无间隔地放置每张图像.

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.

这篇关于免费裁剪图像android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆