BufferedImage img;
public void hue_change(int hue) {
int size = img.getWidth()*img.getHeight();
int rgb[] = new int[size];
int pixel, a, r, g, b, x, max, min, delta;
float h = 0;
img.getRGB(0, 0, img.getWidth(), img.getHeight(), rgb, 0, img.getWidth());
for (int i=0;i<size;++i) {
pixel = rgb[i];
a = (pixel & 0xff000000);
r = (pixel & 0xff0000 ) >> 16;
g = (pixel & 0xff00 ) >> 8;
b = (pixel & 0xff );
max = (r > g) ? r : g; max = (max > b) ? max : b;
min = (r > g) ? g : r; min = (min > b) ? b : min;
delta = max - min;
h = 0;
if (delta == 0) continue;
if (r == max) {
h = (g - b)/(float)delta;
} else if (g == max) {
h = (b - r)/(float)delta + 2;
} else if (b == max) {
h = (r - g)/(float)delta + 4;
}
h *= 60;
if (h < 0) h += 360;
x = (int)h - hue;
x %= 360; if (x < 0) x += 360;
r = Math.abs(x-180)*delta/60-delta;
x = (int)h - hue + 240;
x %= 360; if (x < 0) x += 360;
g = Math.abs(x-180)*delta/60-delta;
x = (int)h - hue + 120;
x %= 360; if (x < 0) x += 360;
b = Math.abs(x-180)*delta/60-delta;
if (r > max) r = max; if (r < min) r = min;
if (g > max) g = max; if (g < min) g = min;
if (b > max) b = max; if (b < min) b = min;
pixel = a|(r<<16)|(g<<8)|b;
rgb[i] = pixel;
}
img.setRGB(0, 0, img.getWidth(), img.getHeight(), rgb, 0, img.getWidth());
}