在JAI中将图像分成四个相等的部分

问题描述 投票:1回答:3

请给我一些编码,将图像从Java Advanced Imaging的中心分成四个部分。

java imaging
3个回答
2
投票

不确定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
  };
}

1
投票

在使用四个Java2D的Sun的unequal parts *演示中有一个有趣的trompe-l'oeil。

*参见Images标签的右下象限。


1
投票

在示例中,宽度必须首先高于高度。那是:

source.getSubimage(0, 0,width, height ), // top left
source.getSubimage(width, 0, width, height), // top right
source.getSubimage(0, height, width, height), // bottom left
© www.soinside.com 2019 - 2024. All rights reserved.