Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Color tinting algorithm in C#

4.00/5 (5 votes)
19 Nov 2009CPOL 18.3K  
I love Code Project, this site has helped me quite a number of times. So whenever I have something I feel is worthwhile I will post it.The other day I needed an algorithm to tint one color with another by a percentage amount. So here it is if anyone needs it. private static Color Tint(Color

I love Code Project, this site has helped me quite a number of times. So whenever I have something I feel is worthwhile I will post it.

The other day I needed an algorithm to tint one color with another by a percentage amount. So here it is if anyone needs it.

private static Color Tint(Color source, Color tint, decimal alpha)
{
  //(tint -source)*alpha + source
  var red = Convert.ToInt32(((tint.R - source.R) * alpha + source.R));
  var blue = Convert.ToInt32(((tint.B - source.B) * alpha + source.B));
  var green = Convert.ToInt32(((tint.G - source.G) * alpha + source.G));
  return Color.FromArgb(255, red, green, blue);
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)