hi guys, i need your help once more!
The aim of the game is to modify the color of pixels in an image… More precisely, to change the hue and the saturation to custom values.
I found no simple way to achieve this, the only one is the horrible code following!
Color pixelColor;
float[] hsb = new int[3];
int alpha;
for (int x=0; x<width; x++)
for (int y=0; y<height; y++)
{
// Take pixel color information.
int rgb = image.getRGB(x,y);
pixelColor = new Color(rgb);
// get alpha
alpha = pixelColor.getAlpha();
// get brightness (is put in hsb[2])
Color.RGBtoHSB(
pixelColor.getRed(),
pixelColor.getGreen(),
pixelColor.getBlue(),
hsb);
// Create the new color
pixelColor = Color.getHSBColor(myHue, mySaturation, hsb[2]);
// Create the new color again with the rigth alpha
pixelColor = new Color(
pixelColor.getRed(),
pixelColor.getGreen(),
pixelColor.getBlue(),
alpha);
// Get it back again in RGB code
rgb = pixelColor.getRGB();
// Change the pixel's color
image.setRGB(rgb);
}
Isn’t there something simplier to do it?!?!