Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void floodFill(Bitmap buffer, int x, int y, Color start, Color end) {
- // Scan-line method -- Thanks to Runer112 for providing me with the link
- // to Lode's tutorial (and thanks to Lode for writing said tutorial), which
- // served as the basis for this, and jacobly for helping to fix it.
- // areColorValuesEqual(Color,Color): compares ARGB values
- if (areColorValuesEqual(start, end)) return;
- if (areColorValuesEqual(buffer.GetPixel(x, y), end)) return;
- // Line from current position to bottom
- int y1 = y;
- while (y1 < buffer.Height && areColorValuesEqual(buffer.GetPixel(x, y1), start)) {
- buffer.SetPixel(x, y1, end);
- y1++;
- }
- int maxY = y1 - 1; //Store the maximum Y value
- // Line from current position to top
- y1 = y - 1;
- while (y1 >= 0 && areColorValuesEqual(buffer.GetPixel(x, y1), start)) {
- buffer.SetPixel(x, y1, end);
- y1--;
- }
- int minY = y1 + 1; //Store the minimum Y value
- for (int i = minY; i < maxY; i++) { //From the minimum to the maximum
- if (x > 0 && areColorValuesEqual(buffer.GetPixel(x - 1, i), start)) { //If we can check left and it hasn't been filled left,
- floodFill(buffer, x - 1, i, start, end); //Fill to the left
- }
- if (x < buffer.Width - 1 && areColorValuesEqual(buffer.GetPixel(x + 1, i), start)) {//If we can go right and it hasn't been filled right,
- floodFill(buffer, x + 1, i, start, end); //Fill to the right
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement