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.
You made a mistake in your call to Color.RGBtoHSB
.
You wrote:
Color.RGBtoHSB(pix.getRGB(),pix.getGreen(),pix.getBlue(),hsb);
You probably wanted:
Color.RGBtoHSB(pix.getRed(),pix.getGreen(),pix.getBlue(),hsb);