0

我遇到了如何找到图像中心并将其写入不同图像的问题。情况是我有图像(例如 800X500),我需要使用 img.getSubimage(x, y, w, h) 精确裁剪(50X50 或 70X70)中心。

每次新图像的尺寸都会不同。

如何计算 X 和 Y 以从图像中心获得 50X50 subImage?

提前致谢。

img.getSubimage(x, y, w, h) - X 和 Y 不是中心坐标。 * @param x *指定矩形区域左上角的X坐标 * @param y *指定矩形区域左上角的Y坐标

4

1 回答 1

5
int bigwidth = 800;
int bigheight = 500;
int cropwidth = 70;
int cropheight = 70;
img.getSubimage((bigwidth - cropwidth) / 2, (bigheight - cropheight) / 2, cropwidth, cropheight);
于 2013-08-21T17:00:25.400 回答