Gets the saturation value from an RGB - CSharp System.Drawing

CSharp examples for System.Drawing:Color RGB

Description

Gets the saturation value from an RGB

Demo Code


using Microsoft.Xna.Framework;
using System;/*from  ww w .java 2  s . co m*/

public class Main{
        /// <summary>
        /// Gets the saturation value from an RGB
        /// </summary>
        /// <param name="R">Red</param>
        /// <param name="G">Green</param>
        /// <param name="B">Blue</param>
        /// <returns></returns>
        public static double getSat(int R, int G, int B)
        {
            double C;
            double alph = 0.5*(2*R-(G+B));
            double beta = Math.Sqrt(3)*0.5*(G-B);
            C = Math.Sqrt(Math.Pow(alph,2) + Math.Pow(beta,2));
            if(C==0) return 0;
            return (C/ getVal(R,G,B));
        }
}

Related Tutorials