Get Color Distance - CSharp System.Drawing

CSharp examples for System.Drawing:Color

Description

Get Color Distance

Demo Code


using System.Windows.Media;

public class Main{
        public static double GetColorDistance(Color a, Color b)
      {//from   www  .  ja  v a2s  .co  m
         return System.Math.Sqrt(System.Math.Pow(a.R - b.R, 2) + System.Math.Pow(a.G - b.G, 2) + System.Math.Pow(a.B - b.B, 2));
      }
        public static double GetColorDistance(byte aR, byte aG, byte aB, Color b)
      {
         return System.Math.Sqrt(System.Math.Pow(aR - b.R, 2) + System.Math.Pow(aG - b.G, 2) + System.Math.Pow(aB - b.B, 2));
      }
        public static double GetColorDistance(byte aR, byte aG, byte aB, byte bR, byte bG, byte bB)
      {
         return System.Math.Sqrt(System.Math.Pow(aR - bR, 2) + System.Math.Pow(aG - bG, 2) + System.Math.Pow(aB - bB, 2));
      }
}

Related Tutorials