Advertisement
Guest User

Untitled

a guest
Jul 15th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. namespace Get_Color_Count_From_Image
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. var img = Image.FromFile("image.png");
  11. List<Color> colors = new List<Color>();
  12. using (Bitmap bmp = new Bitmap(img))
  13. {
  14. for (int i = 0; i < bmp.Width; i++)
  15. {
  16. for (int j = 0; j < bmp.Height; j++)
  17. {
  18. Color clr = bmp.GetPixel(i, j);
  19. if (colors.IndexOf(clr) == -1)
  20. {
  21. colors.Add(clr);
  22. }
  23. }
  24. }
  25. }
  26. Console.WriteLine(colors.Count);
  27. Console.ReadKey();
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement