我必须做一个包含一个带有图像的面板的Java程序。用户在图像上单击两次后,程序必须增加这两个点之间的图像部分的对比度,并减少其余部分。我需要一些关于如何做到这一点的一般性说明。
我知道我将不得不使用Java 2D,我知道如何增加或减少图像的对比度。但是,我不知道如何将图像分成两部分。
提前感谢所有回答的人:)
答案 0 :(得分:0)
您可以使用这段代码。它将图像分割成单元格,它可以很好地完成工作:)
public static BufferedImage[] splitImage(BufferedImage img, int cols, int rows) {
int wCell = img.getWidth()/cols;
int hCell = img.getHeight()/rows;
int imageBlockIndex = 0;
BufferedImage imgs[] = new BufferedImage[wCell *hCell ];
for(int y = 0; y < rows; y++) {
for(int x = 0; x < cols; x++) {
imgs[imageBlockIndex] = new BufferedImage(wCell , hCell , img.getType());
// Draw only one portion/cell of the image
Graphics2D g = imgs[imageBlockIndex].createGraphics();
g.drawImage(img, 0, 0, wCell , hCell , wCell *x,
hCell *y, wCell *x+wCell , hCell *y+hCell , null);
g.dispose();
imageBlockIndex++;
}
}
return imgs;
}