如何将图像分为两部分,增加其中一部分的对比度并降低另一部分的对比度?

问题描述:

我必须做一个Java程序,它包含一个包含图像的面板。用户在图像上单击两次后,程序必须增加图像中包含在这两个点之间的部分的对比度,并减少其余部分。我需要一些关于如何做到这一点的一般说明。如何将图像分为两部分,增加其中一部分的对比度并降低另一部分的对比度?

我知道我将不得不使用Java 2D,并且我知道如何增加或减少图像的对比度。但是,我不确定如何将图像分成两部分。

在此先感谢大家谁回答:)

您可以使用这段代码。它将图像分解成单元格,并且它的工作非常好:)

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; 
}