0

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

4

1 回答 1

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

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

于 2012-12-08T18:54:11.603 回答