private static Bitmap BuildLines(Bitmap bitmap) { int width = bitmap.Width, height = bitmap.Height; Queue <Pixel> queueColors = new Queue <Pixel>(); Queue <Pixel> bufColors = new Queue <Pixel>(); Pixel[,] pixels = BitmapOperations.MakePixelArray(bitmap); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { if (!BitmapOperations.IsWhiteColor(pixels[i, j].Color) && !pixels[i, j].IsChecked) { queueColors.Enqueue(pixels[i, j]); bufColors.Enqueue(pixels[i, j]); while (queueColors.Count != 0) { BitmapOperations.FindNeighbours(pixels, queueColors); BitmapOperations.SaveToBuf(queueColors, bufColors); } List <Pixel> edges = EdgeCoords(bufColors); objectEdges.Add(edges); //BitmapOperations.PaintCells(bitmap, edges, Color.Black); bufColors.Clear(); } } } DrawLines(objectEdges, bitmap); return(bitmap); }
private static Bitmap FindAndColor(Bitmap bitmap) { int height = bitmap.Height, width = bitmap.Width; int iterator = 0; List <Color> colors = new List <Color>() { Color.Red, Color.Green, Color.Blue, Color.Yellow, Color.Lime, Color.Pink, Color.Aqua }; // Queue <Pixel> queueColors = new Queue <Pixel>(); Queue <Pixel> bufColors = new Queue <Pixel>(); Pixel[,] pixels = BitmapOperations.MakePixelArray(bitmap); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { if (!BitmapOperations.IsWhiteColor(pixels[i, j].Color) && !pixels[i, j].IsChecked) { queueColors.Enqueue(pixels[i, j]); bufColors.Enqueue(pixels[i, j]); if (iterator == colors.Count) { iterator = 0; } while (queueColors.Count != 0) { BitmapOperations.FindNeighbours(pixels, queueColors); BitmapOperations.SaveToBuf(queueColors, bufColors); BitmapOperations.PaintCells(bitmap, queueColors.ToList(), colors[iterator]); } iterator++; if (!IsMoreThan20(bufColors.Count)) { BitmapOperations.PaintCells(bitmap, bufColors.ToList(), Color.White); } bufColors.Clear(); } } } return(bitmap); }
private static void RowColmChecking(ref Bitmap bitmap, int row, int colmn, bool state) { Queue <Pixel> queueColors = new Queue <Pixel>(); Pixel[,] pixels = BitmapOperations.MakePixelArray(bitmap); if (state) { for (int j = 0; j < colmn; j++) { if (!BitmapOperations.IsWhiteColor(pixels[j, row].Color)) { //pixels[j, row].IsChecked = true; queueColors.Enqueue(pixels[j, row]); while (queueColors.Count != 0) { BitmapOperations.FindNeighbours(pixels, queueColors); BitmapOperations.PaintCells(bitmap, queueColors.ToList(), Color.White); } } } } else { for (int j = 0; j < row; j++) { if (!BitmapOperations.IsWhiteColor(pixels[colmn, j].Color)) { //pixels[colmn, j].IsChecked = true; queueColors.Enqueue(pixels[colmn, j]); while (queueColors.Count != 0) { BitmapOperations.FindNeighbours(pixels, queueColors); BitmapOperations.PaintCells(bitmap, queueColors.ToList(), Color.White); } } } } }