Change Java Image Saturation

I am trying to change the saturation of a specific image in Java. I already know how to edit the hue and brightness of a pixel, but I donโ€™t understand how to do it. Here's the loop that I use to cycle through each of the pixels if you need to know that. I know this is bad for performance, but it is temporary. Loop:

for(int y = 0; y < height; y++) { for(int x = 0; x < width; x++) { int pixel = image.getRGB(x, y); int r = (pixel >> 16) & 0xFF; int g = (pixel >> 8) & 0xFF; int b = (pixel) & 0xFF; //Adjust saturation: //????????????????????? } } 

In short, I'm not sure how to change the pixel saturation, but I want to know how to do this. The loop that I use above works fine, so there is no problem. Thank you !: D

+5
source share
1 answer

You can use:

 int red = ...; int green = ...; int blue = ...; float[] hsb = Color.RGBtoHSB(red, green, blue, null); float hue = hsb[0]; float saturation = hsb[1]; float brightness = hsb[2]; /* then change the saturation... */ int rgb = Color.HSBtoRGB(hue, saturation, brightness); red = (rgb>>16)&0xFF; green = (rgb>>8)&0xFF; blue = rgb&0xFF; 
+1
source

Source: https://habr.com/ru/post/1242488/


All Articles