0

i want to crop the bitmap that is in the square

How do i get a part of a bitmap (which is in a imageview) saved as shown in the picture. All i need to do is to crop a particular image using (x,y) coordinates. all that i have is x,y coordinates and nothing else to select the cropped area. Between, user doesnt select the crop area. So its enough if its static. yellow part is an imageview(not the whole activity)

1 Answer 1

7

just create a new Bitmap and use the original one as the source. Insert as x and y coordinates 0 and your custom width and hight. public static Bitmap createBitmap (Bitmap source, int x, int y, int width, int height) .

This post describes how to get a Bitmap from a view, in your case the imageview you want to crop. Converting a view to Bitmap without displaying it in Android?

4
  • 1
    i tried this, its working. but my problem is i have adapted pinch zoom (multi touch) so i have to crop the zoomed image(only visible part of image) but its cropping the entire image... any idea? Dec 20, 2011 at 6:27
  • sorry i don´t have the time right now to write a snippet, but you have to enable the drawingcache for your imageview and extract the bitmap by Bitmap newBitmap = imageView.getDrawingCache(); i hope this will help you
    – andreasg
    Dec 20, 2011 at 10:00
  • I have already tried that. its returning a part of the original image and not zoomed image Dec 20, 2011 at 10:03
  • how do you scale the content of the image view?
    – andreasg
    Dec 20, 2011 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.