protected void Count_Pixels_On_A_Line_Change_It_To_Red(int j, Line line) { for (int i = line.FirstPixel; i <= line.LastPixel; i++) { if (CompareColors(image.GetPixel(i, j), Color.Black)) { //To count black pixel, then set it to red SizeOfShape++; image.SetPixel(i, j, Color.Red); //To find out if a black pixel on top of red one, then store it to BlackPixelList if (j > 0 && CompareColors(image.GetPixel(i, j - 1), Color.Black)) { var cell = new BlackPixel(i, j - 1); BlackPixelList.Add(cell); } if (BlackPixelList.Count > 0) { //To find out if this pixel is in BlackPixelList, then remove it var cell = new BlackPixel(i, j); if (BlackPixelList.Contains(cell)) { BlackPixelList.Remove(cell); } } } //End when it is while pixel else if (CompareColors(image.GetPixel(i, j), Color.White)) { break; } } }
protected Line Find_Start_End_Pixel_On_A_Line(BlackPixel cell) { var pict = image.Size; var line = new Line(); if (CompareColors(image.GetPixel(cell.X, cell.Y), Color.Black)) { //Find first black pixel in a row for (int b = cell.X; b >= 0; b--) { if (CompareColors(image.GetPixel(b, cell.Y), Color.Black)) { line.FirstPixel = b; line.LastPixel = b; } else { break; } } //Find last black pixel in a row for (int e = cell.X; e < pict.Width; e++) { if (CompareColors(image.GetPixel(e, cell.Y), Color.Black)) { line.LastPixel = e; } else { break; } } } return(line); }