Reputation: 476
I want to crop my image using 4 XY coordinates in an image. I looked at BufferedImage 's getSubImage method as well however didnt find it useful for my requirement.
Any way to crop it using the 4 coordinates points (x1,y1), (x2,y2), (x3,y3), (x4,y4)
Upvotes: 1
Views: 3833
Reputation: 350
You can refer to http://sanjaal.com/java/395/java-graphics/cropping-an-image-in-java-sampletutorial-with-source-code/ for rectangular cropping. Since you have written in your post that you want to crop your image through four x, y co-ordinates I suppose that you want to do non rectangular cropping. Refer to Android - Crop an image from multipoints or How to crop an image in between four points on Android or http://www.java-forums.org/awt-swing/30097-image-cropping.html
Best of Coding!
Upvotes: 0
Reputation: 4319
A rectangle in plane with sides parallel to axes can be characterized by two points : top left (x1, y1)
and bottom right (x2, y2)
corners. So just use getSubImage()
appropriately :
/*
(x1, y1) ....... (w = y2-y1) .. (x2, y1)
.
.
(h = y2-y1)
.
.
(x1, y2) .......................(x2, y2) */
BufferedImage myImaxe;
myImage.getSubImage(x1, y1, (x2-x1), (y2-y1));
Upvotes: 1