Get HSV Color Saturation - CSharp System.Drawing

CSharp examples for System.Drawing:Color HSV

Description

Get HSV Color Saturation

Demo Code


using System.Windows.Media;

public class Main{
        /// <summary>
      /// Get HSV Saturation
      /// </summary>
      /// <param name="red">RGB -> R (0..256)</param>
      /// <param name="green">RGB -> G (0..256)</param>
      /// <param name="blue">RGB -> B (0..256)</param>
      /// <returns>HSV -> S (0..100)</returns>
      public static double GetSaturation(int red, int green, int blue)
      {/*from w  w w.  j  a v a 2 s. c o m*/
         int min = System.Math.Min(System.Math.Min(red, green), blue);
         int max = System.Math.Max(System.Math.Max(red, green), blue);

         if (max == 0)
            return 0;

         return 100 * (max - min * 1.0) / max;
      }
}

Related Tutorials