是否有可能找到相反的顏色對於給定的RGB組合?例如,我在基本應用程序中有以下內容。
myColor red = new myColor(0, true), green = new myColor(0, true), blue = new myColor(0, true), theColor;
Random rand = new Random(DateTime.Now.Millisecond);
int color = 0;
void timer_Tick(object sender, EventArgs e)
{
switch (color)
{
case 0: theColor = red; break;
case 1: theColor = green; break;
case 2: theColor = blue; break;
}
if (theColor.Up)
{
theColor.Value += 0.01F;
if (theColor.Value + 0.01F > 1) { theColor.Up = false; color = rand.Next(3); }
}
else if (!theColor.Up)
{
theColor.Value -= 0.01F;
if (theColor.Value - 0.01F < 0) { theColor.Up = true; color = rand.Next(3); }
}
label1.Text = red.Value + Environment.NewLine + green.Value + Environment.NewLine + blue.Value;
FadeBackground(red.Value, green.Value, blue.Value);
}
void FadeBackground(float red, float green, float blue)
{
BackColor = Color.FromArgb((int)((1 - red) * 255), (int)((1 - green) * 255), (int)((1 - blue) * 255));
label1.ForeColor = BackColor;
//label1.BackColor;
}
class myColor
{
public myColor(float value, bool up)
{
Value = value;
Up = up;
}
public float Value;
public bool Up;
}
但我希望能夠更改標籤的背景顏色,使其始終與任何背景相反或相反。
在此先感謝,我希望這是有道理的。
相反的顏色? #888888的反義詞是什麼? FFFFFF和00000與它距離相等......我真的不知道相反的顏色是什麼.. – 2010-07-30 20:11:41
無論背景是什麼顏色,您都想確保閱讀標籤,對嗎? – Justin 2010-07-30 20:12:50