title: show most used color in an image
body: <p>So somebody helped me to make this code which will tell me the most used color in a photo:</p>
  
  <pre><code>class PictureAnalysis
  {
      public static List&lt;Color&gt; TenMostUsedColors { get; private set; }
      public static List&lt;int&gt; TenMostUsedColorIncidences { get; private set; }
  
      public static Color MostUsedColor { get; private set; }
      public static int MostUsedColorIncidence { get; private set; }
  
      private static int pixelColor;
  
      private static Dictionary&lt;int, int&gt; dctColorIncidence;
  
      public static void GetMostUsedColor(Bitmap theBitMap)
      {
          TenMostUsedColors = new List&lt;Color&gt;();
          TenMostUsedColorIncidences = new List&lt;int&gt;();
  
          MostUsedColor = Color.Empty;
          MostUsedColorIncidence = 0;
  
          // does using Dictionary&lt;int,int&gt; here
          // really pay-off compared to using
          // Dictionary&lt;Color, int&gt; ?
  
          // would using a SortedDictionary be much slower, or ?
  
          dctColorIncidence = new Dictionary&lt;int, int&gt;();
  
          // this is what you want to speed up with unmanaged code
          for (int row = 0; row &lt; theBitMap.Size.Width; row++)
          {
              for (int col = 0; col &lt; theBitMap.Size.Height; col++)
              {
                  pixelColor = theBitMap.GetPixel(row, col).ToArgb();
  
                  if (dctColorIncidence.Keys.Contains(pixelColor))
                  {
                      dctColorIncidence[pixelColor]++;
                  }
                  else
                  {
                      dctColorIncidence.Add(pixelColor, 1);
                  }
              }
          }
  
          // note that there are those who argue that a
          // .NET Generic Dictionary is never guaranteed
          // to be sorted by methods like this
          var dctSortedByValueHighToLow = dctColorIncidence.OrderByDescending(x =&gt; x.Value).ToDictionary(x =&gt; x.Key, x =&gt; x.Value);
  
          // this should be replaced with some elegant Linq ?
          foreach (KeyValuePair&lt;int, int&gt; kvp in dctSortedByValueHighToLow.Take(10))
          {
              TenMostUsedColors.Add(Color.FromArgb(kvp.Key));
              TenMostUsedColorIncidences.Add(kvp.Value);
          }
  
          MostUsedColor = Color.FromArgb(dctSortedByValueHighToLow.First().Key);
          MostUsedColorIncidence = dctSortedByValueHighToLow.First().Value;
      }
  
  }
  </code></pre>
  
  <p>and I am trying to implement like this but I don't really know what I should do to show me the most used color?</p>
  
  <pre><code>string filep = @"C:\Users\User\Desktop\Gallery\image" + NumberOfClick.ToString() + "cropped.png";
  
                  Bitmap bMap = Bitmap.FromFile(filep) as Bitmap;
  
                  PictureAnalysis.GetMostUsedColor(bMap);
  </code></pre>
  
  <p>I want to determine the most used color from a "real" photo like this one: <a href="https://i.stack.imgur.com/gsna7.jpg" rel="nofollow noreferrer">I am cropping her "jacket" from the photo and I want a program that determines it as it is black</a></p>