- Код: Выделить всё
public static HSB RGB2HSB(RGB Color)
{
HSB H_S_B = new HSB();
double MinRGB, MaxRGB, Delta;
double H, S, B;
H = 0.0;
MinRGB = Math.Min(Math.Min(Color.Red, Color.Green), Color.Blue);
MaxRGB = Math.Max(Math.Max(Color.Red, Color.Green), Color.Blue);
Delta = MaxRGB - MinRGB;
B = MaxRGB;
if (MaxRGB != 0.0)
{
S = 255.0 * Delta / MaxRGB;
}
else
{
S = 0.0;
}
if (S != 0.0)
{
if (Color.Red == MaxRGB)
{
H = (Color.Green - Color.Blue) / Delta;
}
else if (Color.Green == MaxRGB)
{
H = 2.0 + (Color.Blue - Color.Red) / Delta;
}
else if (Color.Blue == MaxRGB)
{
H = 4.0 + (Color.Red - Color.Green) / Delta;
}
}
else
{
H = -1.0;
H = H * 60.0;
}
if (H < 0)
{
H = H + 360.0;
}
H_S_B.Hue = H;
H_S_B.Saturation = S * 100 / 255;
H_S_B.Brightness = B * 100 / 255;
return H_S_B;
}
А как переконвертировать HSB в RGB?