0

How to implement freehand cropping of image in android rather than using usual rectangular cropping?

  • here you can find how to get area from image :-http://stackoverflow.com/questions/10834109/java-create-a-shape-from-border-around-image – Ali Imran Dec 08 '12 at 18:28
  • more help is here :-http://stackoverflow.com/questions/12705637/implemanting-freehand-crop-in-android – Ali Imran Dec 08 '12 at 18:31

1 Answers1

2

You do it in the following way.

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

after getting the path array list you can create a new bitmap and fill that bitmap with pixels in this path by reading pixel from original image.

Ali Imran
  • 8,927
  • 3
  • 39
  • 50