制作Freehand Cropping Android

时间:2012-12-08 18:19:28

标签: android

如何在android中实现图像的徒手裁剪,而不是使用通常的矩形裁剪?

1 个答案:

答案 0 :(得分:2)

您可以通过以下方式进行操作。

  BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
        Bitmap bitmap = drawable.getBitmap();


        ArrayList<Point> regionPoints = new ArrayList<Point>();  // the output region to be filled affter the crop;

       int h  = bitmap.getHeight();
       int w  =  bitmap.getWidth();
       boolean isInsideRegion = false;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
               if(bitmap.getPixel(j, h) == Color.WHITE){
                   regionPoints.add(new Point(j, h)); // the points where pixel color is white 
               }                                      // as pixels are replaced in orinal image while the finger is mover overe the image
            }                                         // write the pixel replacement code your self Google for it :)
        }

获取路径数组列表后,您可以创建一个新的位图,并通过从原始图像中读取像素来填充该路径中的像素。