'Is there an easy way to blend two System.Drawing.Color values?
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?
Solution 1:[1]
If you want to blend colours in a way that looks more natural to the human eye, you should consider working in a different colour space to RGB, such as L*a*b*, HSL, HSB.
There a great code project article on colour spaces with examples in C#.
You may like to work with L*a*b*, as it was designed to linearise the perception of color differences and should therefore produce elegant gradients.
Solution 2:[2]
I am not entirely sure what you're trying to do with blending, but you could look into alpha blending http://en.wikipedia.org/wiki/Alpha_compositing.
Solution 3:[3]
I think its easier to blend an array of colors, in case you want to blend more then 2 Here is my function:
private Color colorBlend(List<Color> clrArr)
{
int r = 0;
int g = 0;
int b = 0;
foreach(Color color in clrArr)
{
r += color.R;
g += color.G;
b += color.B;
}
r = r / clrArr.Count;
g = g / clrArr.Count;
b = b / clrArr.Count;
return Color.FromArgb(r, g, b);
}
The array must be as a List of color Use :
List<Color> colorList = new List<Color>();
colorList.Add(Color.Red);
colorList.Add(Color.Blue);
picturebox.backColor = colorBlend(colorList);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Aurojit Panda |
| Solution 3 | Gazgoh |
