public static void Main()
var originalColor = ColorTranslator.FromHtml("#01aeb9");
var color = Color.Purple;
var changedColor = FromAhsb(originalColor.A, color.GetHue(), originalColor.GetSaturation(), originalColor.GetBrightness());
Console.WriteLine(ColorTranslator.ToHtml(changedColor));
public static Color FromAhsb(int alpha, float hue, float saturation, float brightness)
if (0 > alpha || 255 < alpha)
throw new ArgumentOutOfRangeException("alpha", alpha,
"Value must be within a range of 0 - 255.");
if (0f > hue || 360f < hue)
throw new ArgumentOutOfRangeException("hue", hue,
"Value must be within a range of 0 - 360.");
if (0f > saturation || 1f < saturation)
throw new ArgumentOutOfRangeException("saturation", saturation,
"Value must be within a range of 0 - 1.");
if (0f > brightness || 1f < brightness)
throw new ArgumentOutOfRangeException("brightness", brightness,
"Value must be within a range of 0 - 1.");
return Color.FromArgb(alpha, Convert.ToInt32(brightness * 255),
Convert.ToInt32(brightness * 255), Convert.ToInt32(brightness * 255));
int iSextant, iMax, iMid, iMin;
fMax = brightness - (brightness * saturation) + saturation;
fMin = brightness + (brightness * saturation) - saturation;
fMax = brightness + (brightness * saturation);
fMin = brightness - (brightness * saturation);
iSextant = (int)Math.Floor(hue / 60f);
hue -= 2f * (float)Math.Floor(((iSextant + 1f) % 6f) / 2f);
fMid = hue * (fMax - fMin) + fMin;
fMid = fMin - hue * (fMax - fMin);
iMax = Convert.ToInt32(fMax * 255);
iMid = Convert.ToInt32(fMid * 255);
iMin = Convert.ToInt32(fMin * 255);
return Color.FromArgb(alpha, iMid, iMax, iMin);
return Color.FromArgb(alpha, iMin, iMax, iMid);
return Color.FromArgb(alpha, iMin, iMid, iMax);
return Color.FromArgb(alpha, iMid, iMin, iMax);
return Color.FromArgb(alpha, iMax, iMin, iMid);
return Color.FromArgb(alpha, iMax, iMid, iMin);