1

Why does altering brightness changes color in HSB color model? Here's my code:

for (int y=0; y<height; y++)
    for (int x=0; x<width; x++) {
        Color pix = image.getPixel(x, y);
            float[] hsb = new float[3];
            Color.RGBtoHSB(pix.getRGB(),pix.getGreen(),pix.getBlue(),hsb);
            Color newColor = new Color(Color.HSBtoRGB(hsb[0], hsb[1],(float)0.5));
                image.setPixel(x, y, newColor);
        }

The code assigns value of 0.5 to brightness of each pixel in image.

4

1 回答 1

1

您在调用 时犯了一个错误Color.RGBtoHSB

你写了:

Color.RGBtoHSB(pix.getRGB(),pix.getGreen(),pix.getBlue(),hsb);

你可能想要:

Color.RGBtoHSB(pix.getRed(),pix.getGreen(),pix.getBlue(),hsb);
于 2014-02-19T02:53:10.663 回答