使用複製的功能from here,您可以將色調轉換回RGB顏色。這個函數假設所有的輸入和輸出都是0..1的比例,所以你需要用color.GetHue()除以255.在函數的下面是一些使用一組百分比的示例代碼;在您選擇的用戶界面中實施DisplayColor以查看結果。
public static void HSVToRGB(double H, double S, double V, out double R, out double G, out double B)
{
if (H == 1.0)
{
H = 0.0;
}
double step = 1.0/6.0;
double vh = H/step;
int i = (int) System.Math.Floor(vh);
double f = vh - i;
double p = V*(1.0 - S);
double q = V*(1.0 - (S*f));
double t = V*(1.0 - (S*(1.0 - f)));
switch (i)
{
case 0:
{
R = V;
G = t;
B = p;
break;
}
case 1:
{
R = q;
G = V;
B = p;
break;
}
case 2:
{
R = p;
G = V;
B = t;
break;
}
case 3:
{
R = p;
G = q;
B = V;
break;
}
case 4:
{
R = t;
G = p;
B = V;
break;
}
case 5:
{
R = V;
G = p;
B = q;
break;
}
default:
{
// not possible - if we get here it is an internal error
throw new ArgumentException();
}
}
}
Color min = Color.Blue;
Color max = Color.Green;
float minHue = min.GetHue()/255;
float maxHue = max.GetHue()/255;
float scale = maxHue - minHue;
float[] percents = new float[] { .05F, .15F, .40F, .70F, .85F, .95F };
foreach (var pct in percents) {
float curHue = minHue + (scale * pct);
double r, g, b;
HSVToRGB(curHue, 1.0, 1.0, out r, out g, out b);
Color curColor = Color.FromArgb((int)(r * 255), (int)(g * 255), (int)(b * 255));
DisplayColor(curColor);
}
請清除你的問題,我真的不明白你在問什麼! – TDaver 2011-03-06 14:50:53
希望能夠解釋我之後的事情。如果還有不清楚的地方請讓我知道。 – Kasy 2011-03-06 14:53:01
這看起來是回答,你還需要別的嗎? – 2011-03-13 22:06:18