In my class we are doing some color conversions. I have been able to figure out simple color conversions like red, blue, green, purple, and yellow but I have been unable to figure out how to make a color like orange or brown. I tried multiplying by a decimal, such as g*0.6 but then I end up with a type mismatch (double instead of int).
public void toYellow() {
//convert to yellow
for(int y = 0; y < img.getHeight(); y++){
for(int x = 0; x < img.getWidth(); x++){
int p = img.getRGB(x,y);
int a = (p>>24)&0xff;
int r = (p>>16)&0xff;
int g = (p>>8)&0xff;
int b = p&0xff;
//set blue to zero
p = (a<<24) | (r<<16) | (g<<8) | 0;
img.setRGB(x, y, p);
setColor("Yellow");
}
}
}
(int)(g*0.6)
to cast the double back to an int – Lou Franco