Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 818
Matt Avatar asked Sep 15 '10 22:09

Matt


People also ask

What is it called when you blend from one color to another?

Ombré /ˈɒmbreɪ/ (literally "shaded" in French) is the blending of one color hue to another, usually moving tints and shades from light to dark.


1 Answers

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.FromRgb(r, g, b); } 
like image 109
Timwi Avatar answered Sep 29 '22 18:09

Timwi