Java程序,在HSV中输入颜色代码并输出等效的RGB代码,反之亦然



我正试图编写一个从color rgb转移到hsv的代码,但编译器似乎看不到if条件中的内容这是代码软件包问题2;

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);
   }
}

此处

convert(100.34,0.74,0.78);

变量d的值在之后将是100.34

Hi=(d/60);

变量Hi的值将是1.6723333333333334

在您的if语句中,例如

else 
        if(Hi==1){

您认为变量Hi的值,即1.6723333333333334等于1吗?

建议:我真的不知道你为什么要把double和int进行比较,但你可以进行强制转换,也可以尝试比较这个和那个之间的范围

最新更新