// using getPixel find difference and draw new mutated Draw, change dna public static double getDrawingFitness(MyDnaDrawing newDrawing, Color[,] sourceColors) { double error = 0; using (var b = new Bitmap(MaxWidth, MaxHeight, PixelFormat.Format24bppRgb)) using (Graphics g = Graphics.FromImage(b)) { PolygonDrawing.draw(newDrawing, g, 1); BitmapData bmd1 = b.LockBits(new Rectangle(0, 0, MaxWidth, MaxHeight), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); for (int y = 0; y < MaxHeight; y++) { for (int x = 0; x < MaxWidth; x++) { Color c1 = getPixel(bmd1, x, y); Color c2 = sourceColors[x, y]; double pixelError = getColorFitness(c1, c2); error += pixelError; } } b.UnlockBits(bmd1); } return(error); }
//Render a image drawing public static void draw(MyDnaDrawing drawing, Graphics g, int scale) { g.Clear(Color.Black); foreach (MyDnaPolygon polygon in drawing.Polygons) { drawPolygon(polygon, g, scale); } }