Live Chat Icon For mobile
Live Chat Icon

How do I desaturate a specific color?

Platform: WinForms| Category: Colors

Jon Skeet provided this solution in the MS Windows Forms News Group.


[C#]
double greyLevel = original.R * 0.299 + original.G * 0.587 + original.B * 0.144;
if (greyLevel > 255)
{
    greyLevel = 255;
}

Color desaturated = new Color.FromArgb((byte)greyLevel, (byte)greyLevel, (byte)greyLevel);

[VB.NET]
Dim greyLevel As Double = original.R * 0.299 + original.G * 0.587 + original.B * 0.144
If greyLevel > 255 Then
    greyLevel = 255
End If

Dim desaturated As New Color.FromArgb(CByte(greyLevel), CByte(greyLevel), CByte(greyLevel)) 
 

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.