我想使用图像中的4个XY坐标裁剪图像。我查看了BufferedImage的getSubImage方法,但没有发现它对我的要求有用。
任何方法使用4个坐标点(x1,y1),(x2,y2),(x3,y3),(x4,y4)裁剪它
答案 0 :(得分:0)
平面中具有平行于轴的平面的矩形可以由两个点表征:左上(x1, y1)
和右下(x2, y2)
角。所以只需恰当地使用getSubImage()
:
/*
(x1, y1) ....... (w = y2-y1) .. (x2, y1)
.
.
(h = y2-y1)
.
.
(x1, y2) .......................(x2, y2) */
BufferedImage myImaxe;
myImage.getSubImage(x1, y1, (x2-x1), (y2-y1));
答案 1 :(得分:0)
你可以参考 http://sanjaal.com/java/395/java-graphics/cropping-an-image-in-java-sampletutorial-with-source-code/ 用于矩形裁剪。由于您在帖子中写道要通过四个x,y坐标裁剪图像,我想您想要进行非矩形裁剪。请参阅Android - Crop an image from multipoints或How to crop an image in between four points on Android或http://www.java-forums.org/awt-swing/30097-image-cropping.html
最佳编码!