Fill Bucket in GFX library?

Hi, I am making a Paint app with AdaFruit GFX.

I would like to add a paint bucket, here's how it would work:

You would draw on the screen with different colours (drawCircle at touched place), and you put this paint bucket and until it hit another colour, it would keep colouring. Like all the other types of paint buckets.

I have no idea how to make this work normally or effeciently.

Any help would be appreciated.

Google "flood fill algorithm"

1 Like

Yes @anon73444976 , I know that, but then, is there a function that allows me to check to colour of a cretain pixel?

It's the same colour you wrote there.

@anon73444976 I don't think you understand what I'm trying to say, What I'm trying to say is how do I detect what colour a pixel is without creating a lot of lag

No, I understand what you're trying to say.

Ok! But then I don't understand what you're saying.

What do you mean by


If you haven't kept track of what color you've assigned to pixels, it is possible (at least on some screens) to read the color of a pixel or pixels. Bodmer's library can capture an entire screen (and has a single pixel read, IIRC) GitHub - Bodmer/TFT_eSPI: Arduino and PlatformIO IDE compatible TFT library optimised for the Raspberry Pi Pico (RP2040), STM32, ESP8266 and ESP32 that supports different driver chips

The colour any pixel is, is the very last colour your software wrote to that pixel.

Generally, Adafruit's libraries keep a buffer which contains the data you want displayed. Most of their graphics functions write to the buffer and there is one that actually sends that data from the buffer to the physical display.

Look at the source code for the library. There may already be a readPixel function that tells you what the buffer holds. If not, you can add one.

Adafruit_GFX has a getPixel and getRawPixel function, as well as a getBuffer function that returns a pointer to the buffer.

1 Like

Not necessarily easy to determine, since there are library functions for drawing geometric shapes such as circles where the actual pixel data is generated by the function. Then you would need to look into either the buffer or the display itself.

It is also common on tft displays to be able to overwrite text onto a display without erasing whatever is already on the display, in which case readback from the display itself is needed.

I've never heard of that.
I wonder how that works.

The library just writes the pixels that are needed for the characters, leaving the background as-is. Adafruit has some fonts that also contain background information, allowing you to write text in one color and the background in another, but that is generally not supported in non-Adafruit fonts. To erase the old text you either write the same text in the background color (faster), or use a library function that returns the rectangular area the text occupies and write a box of the background color to that area (fairly slow).

So, the pixels that your software wrote are the colour that your software wrote.

We seem to be agreed.

To a degree. The library handles the work of determining exactly which pixels to write, and does rotation and scaling, as well as proportional spaced fonts with variable font size, so there really is a need to read back from the display.

Thanks, @david_2018 and @anon73444976, with that info, I should be able to make a paint bucket! Thanks again!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.