请给我一些编码,将图像从Java Advanced Imaging的中心分成四个部分。
不确定JAI,但这里是你可能用作JAI输入的BufferedImage
方法。所以也许这适合你的用例
public static BufferedImage[] divide(BufferedImage source) {
// for odd widths or heights, the last row or column will be ignored
// fixing this behaviour is left as an exercise to the eager
int height = source.getHeight() / 2;
int width = source.getWidth() / 2;
return new BufferedImage[] {
source.getSubimage(0, 0, width, height), // top left
source.getSubimage(width, 0, width, height), // top right
source.getSubimage(0, height, width, height), // bottom left
source.getSubimage(width, height, width, height) // bottom right
};
}
在使用四个Java2D的Sun的unequal parts *演示中有一个有趣的trompe-l'oeil。
*参见Images
标签的右下象限。
在示例中,宽度必须首先高于高度。那是:
source.getSubimage(0, 0,width, height ), // top left
source.getSubimage(width, 0, width, height), // top right
source.getSubimage(0, height, width, height), // bottom left