public List <Coordinates> GetLargestArea(string path) { ImageWorker imgWorker = new ImageWorker(); var bmp = imgWorker.GetImage(path); var pixels = imgWorker.GetPixelArray(bmp); InitUncheckedColors(pixels); Coordinates coordinates = new Coordinates(0, 0); List <Coordinates> startingCoordinates = new List <Coordinates>(); startingCoordinates.Add(coordinates); while (CheckedColors.Count < (pixels.GetLength(0) * pixels.GetLength(1))) { var oneColor = GetSameColorsArea(startingCoordinates, pixels); try { startingCoordinates.Clear(); Coordinates crdNew = UncheckedColors.First(); startingCoordinates.Add(crdNew); } catch (InvalidOperationException e) { } if (oneColor.Count > LargestArea.Count) { LargestArea.Clear(); LargestArea = LargestArea.Union(CurrentArea).ToList(); } CheckedColors = CheckedColors.Union(CurrentArea).ToList(); CurrentArea.Clear(); } return(LargestArea); }
static void Main(string[] args) { ImageWorker image = new ImageWorker(); image.GetLargestAreaAsImage("D:/test.bmp", "D:/largest.bmp"); }