有没有一种简单的方法来混合两个的System.Drawing.Color价值观?方法来、价值观、两个、简单

2023-09-03 01:58:05 作者:倾心不倾城

有没有一种简单的方法来混合两个的System.Drawing.Color 值?还是我写我自己的方法采取两种颜色,并结合他们?

Is there an easy way to blend two System.Drawing.Color values? Or do I have to write my own method to take in two colors and combine them?

如果我这样做,怎么可能一去的?

If I do, how might one go about that?

推荐答案

我写了一个实用的方法就是出于这样的目的。 :)

I wrote a utility method for exactly this purpose. :)

/// <summary>Blends the specified colors together.</summary>
/// <param name="color">Color to blend onto the background color.</param>
/// <param name="backColor">Color to blend the other color onto.</param>
/// <param name="amount">How much of <paramref name="color"/> to keep,
/// "on top of" <paramref name="backColor"/>.</param>
/// <returns>The blended colors.</returns>
public static Color Blend(this Color color, Color backColor, double amount)
{
    byte r = (byte) ((color.R * amount) + backColor.R * (1 - amount));
    byte g = (byte) ((color.G * amount) + backColor.G * (1 - amount));
    byte b = (byte) ((color.B * amount) + backColor.B * (1 - amount));
    return Color.FromArgb(r, g, b);
}