public void toHSV3( int red , int green , int blue ){
double maxRGB = FqMath.max( red , green , blue );//
double minRGB = FqMath.min( red , green , blue );
double itemp = maxRGB; //v‘=itemp
double temp = maxRGB - minRGB;//
if( maxRGB == minRGB ){
this.hHSV = 0;
this.sHSV = 0;
this.vHSV = maxRGB / 255;
return;
}
double rtemp = ( itemp - red ) / temp;//r‘=rtemp
double gtemp = ( itemp - green ) / temp;//g‘=gtemp
double btemp = ( itemp - blue ) / temp;//b‘=btemp
this.vHSV = itemp / 255;//v=this.vHSV
this.sHSV = temp / itemp;//s‘=this.sHSV
if( red == maxRGB ){
if( green == minRGB )
this.hHSV = 5 + btemp;
else
this.hHSV = 1 - gtemp;
}
else if( green == maxRGB ){
if( blue == minRGB )
this.hHSV = 1 + rtemp;
else
this.hHSV = 3 - btemp;
}
else if( blue == maxRGB ){
if( red == minRGB )
this.hHSV = 3 + gtemp;
else
this.hHSV = 5 - rtemp;
}
this.hHSV *= 60;
}原文地址:http://blog.csdn.net/guanjungao/article/details/26362035