The most commonly used Flood Fill algorithm. Below is a naive version of it from my old university textbook, Computer Graphics with OpenGL, Hearn Baker, 3rd ed .:
void floodFill4 (int x, int y, int fillColor, int interiorColor) { int color; getPixel(x, y, color); if (color == interiorColor) { setPixel(x,y);
However, for large images, the above will probably give you an error due to recursion for each pixel. Often this algorithm is modified so that it uses iteration to fill in a row of pixels, and then recursively fills the rows above and below. As @kasperjj said, Wikipedia has a good article on this.
Cybis
source share