Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将图像分为两部分,增加其中一部分的对比度,降低另一部分的对比度?_Java_Image Processing_Java 2d - Fatal编程技术网

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

Java 如何将图像分为两部分,增加其中一部分的对比度,降低另一部分的对比度?,java,image-processing,java-2d,Java,Image Processing,Java 2d,我必须做一个Java程序,其中包含一个带有图像的面板。用户在图像上单击两次后,程序必须增加图像中封闭在这两点之间的部分的对比度,并降低其余部分的对比度。我需要一些关于如何做这件事的一般说明 我知道我将不得不使用Java2D,我知道如何增加或减少图像的对比度。但是,我不确定如何将图像分为两部分 提前感谢所有回答的人:)您可以使用这段代码。它将图像分割为单元格,并且工作非常出色:) publicstaticbufferedimage[]splitImage(BufferedImage-img,int

我必须做一个Java程序,其中包含一个带有图像的面板。用户在图像上单击两次后,程序必须增加图像中封闭在这两点之间的部分的对比度,并降低其余部分的对比度。我需要一些关于如何做这件事的一般说明

我知道我将不得不使用Java2D,我知道如何增加或减少图像的对比度。但是,我不确定如何将图像分为两部分


提前感谢所有回答的人:)

您可以使用这段代码。它将图像分割为单元格,并且工作非常出色:)

publicstaticbufferedimage[]splitImage(BufferedImage-img,int-cols,int-rows){
int wCell=img.getWidth()/cols;
int hCell=img.getHeight()/行;
int-imageBlockIndex=0;
BuffereImage imgs[]=新的BuffereImage[wCell*hCell];
对于(int y=0;y
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;
}