Is there an easy way to blend two System.Drawing.Color values?

后端 未结 3 941
执念已碎
执念已碎 2021-01-01 13:20

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

3条回答
  •  清酒与你
    2021-01-01 14:05

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

    /// Blends the specified colors together.
    /// Color to blend onto the background color.
    /// Color to blend the other color onto.
    /// How much of  to keep,
    /// “on top of” .
    /// The blended colors.
    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);
    }
    

提交回复
热议问题