2
我想写一个从颜色rgb转换为hsv的代码,但编译器似乎没有看到里面有什么如果合并 这里的代码 package Problem2;在HSV中输入一个颜色代码并输出等效RGB代码的Java程序,反之亦然
public class HSVRGB {
double d;
double e;
double g;
//Java program that takes an input a color code in HSV and
输出等效的RGB代码,反之亦然。
public static void convert(double d,double e,double g){ /// my hsv inputs that am gonna check
double t;
double p ;
double q;
double f;
double Hi;
//my other variable am gonna use to produce the output
Hi=(d/60);
f=(d/60)-Hi;// here's the formula that will proceed the code
if(Hi==0) {
t=g*(1-(1-f)*e);
p=g*(1-e);
System.out.print("R="+ g + "G=" + t + "b=" + p);
// the given input should pass into the above if condition since its true
}
else
if(Hi==1){
q=g*(1-f*e);
p=1-e;
System.out.print("R="+q+"G="+g+"b="+p);
}
else
if(Hi==2){
p=g*(1-e);
t=g*(1-(1-f)*e);
System.out.print("R="+p + "G="+ g + "B="+t);
}
else
if(Hi==3){
p=g*(1-e);
q=g*(1-(f*e));
System.out.print("R="+p + "G="+q + "B=" + g);
}
else
if(Hi==4){
t=g*(1-(1-f)*e);
p=g*(1-e);
System.out.print("R"+t+"G"+p+"B"+g);
}
else
if(Hi==5){
p=g*(1-e);
q=g*(1-(f*e));
System.out.print("R="+g+ " G"+p+"B="+q);
}
else
System.out.print("Invalid Inpjdsnabfvkdbfjsv,hdbut"); //it only print this message
}
public static void main (String[]args){
convert(100.34,0.74,0.78);
}
}
为什么不使用'Color.getHSBColor范围()'与RGB组件? – trashgod 2014-10-08 01:37:41