Click here to Skip to main content
11,641,081 members (66,125 online)
Click here to Skip to main content

Tagged as

Color tinting algorithm in C#

, 19 Nov 2009 CPOL 8.7K 5
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

NYCChris
Software Developer (Senior)
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150731.1 | Last Updated 19 Nov 2009
Article Copyright 2009 by NYCChris
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid