Example #1
0
        public static int Fitness(Individual <Polygon> popul, Bitmap t)
        {
            Graphics g = null;
            Bitmap   b = null;

            lock (t)
            {
                b = new Bitmap(t.Width, t.Height);
            }

            g = Graphics.FromImage(b);
            Bitmap tempTarget = new Bitmap(1, 1);

            popul.Draw(g);
            lock (t)
            {
                tempTarget = new Bitmap(t);
            }
            int value = 0;

            for (int i = 0; i < tempTarget.Width; i++)
            {
                for (int j = 0; j < tempTarget.Height; j++)
                {
                    var c1 = tempTarget.GetPixel(i, j);
                    var c2 = b.GetPixel(i, j);
                    value += Math.Abs(c1.R - c2.R) +
                             Math.Abs(c1.G - c2.G) +
                             Math.Abs(c1.B - c2.B);
                }
            }
            tempTarget.Dispose();
            return(value);
        }