End Google Ads 201810 - BS.net 01 --> I have just started working in c# so I'm not that familiar with it. Still, I need to build a paint program and I am a bit stuck at Flood Fill. I want to be able to fill areas with an undetermined shape, so I used the SetPixel command, but it sets only one pixel (I'm not entirely sure of this).

For now, I try to change the color from white to one I pick myself. I call the function in the MouseDown function, and I think it should work.

Please help!


bmp = new Bitmap(pictureBox1.Width,pictureBox1.Height);

private void FloodFill(int x, int y)
{
bmp.SetPixel(x, y, DrawColor); //sets the color of the pixel to DrawColor I picked
pictureBox1.Image = bmp; // assigns the bitmap to the picture box; I work with it to be ale to save the picture
if (bmp.GetPixel(x + 1, y) == Color.White) //all four search for each white pixel
FloodFill(x + 1, y);
if (bmp.GetPixel(x, y + 1) == Color.White)
FloodFill(x, y + 1);
if (bmp.GetPixel(x - 1, y) == Color.White)
FloodFill(x - 1, y);
if (bmp.GetPixel(x, y - 1) == Color.White)
FloodFill(x, y - 1);
return;
}

private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
startPoint.X = e.X;
startPoint.Y = e.Y;

FloodFill(e.X, e.Y);
pictureBox1.Image = bmp;

drag = true;
}