14.4 The Paint Bucket Tool

The concept of a “paint bucket” or “flood fill” tool is probably familiar to you from bitmap editors. In Inkscape, the Paint bucket tool works exactly as you would expect: Click in any area bounded on all sides, and it will fill the area with color. Being a vector tool, however, Inkscape’s Paint bucket just creates a new path that “fills in” the area in which you have clicked:

The Paint bucket filling a bounded area

Figure 14-22. The Paint bucket filling a bounded area

It is important to remember that the Paint bucket tool is perceptual, not geometric. That is, when looking for the boundaries around the point you clicked, it identifies as boundaries any visible color nonuniformities. Thus, filling will stop at gradients, blurs, and color boundaries in bitmap objects, but it will ignore any paths or other objects that are fully (or almost) transparent or for any other reason do not stand out from the background.

For example, you can scan a pencil sketch, import the bitmap into Inkscape, and quickly “trace” it by filling all its cells with colors. This is a very convenient and interactive way of digitizing your paper drawings, and it makes the traditional bitmap tracing (the Trace Bitmap dialog, 18.8.2 The Trace Bitmap Dialog) unnecessary in many cases.

Note

Internally, the tool works by performing a bitmap-based flood fill on a screen-resolution rendition of the visible canvas and then tracing the resulting fill into a vector path. The resolution of the rendition used to perform the trace is defined by your current zoom; the closer you are zoomed in to an area, the higher the resolution of the flood fill. So, if the result of the Paint bucket fill is too imprecise, has rounded corners, or doesn’t go into small nooks and crannies where it is supposed to go—just undo it, zoom in closer (but so that the entire area to fill is still visible), and repeat filling from the same point. Conversely, if the fill leaks out through a small gap, zoom out to make the gap less visible and fill again (or use the automatic gap closing parameter, 14.4.5 Closing Gaps).

Filling a bounded area is as easy as switching to the Paint bucket tool ( or ) and clicking inside the area. If you click with , the resulting path will be unioned (12.2 Boolean Operations) with the selected path; this way, if your first attempt did not fill in all of the desired area, just -click the remaining corner to finish it off, as shown in Figure 14-23.

If you click-and-drag, you will fill from all of the points that you pass while dragging (you will see your path visualized by a red line). From each point, the fill spreads to its neighbors with colors similar to that point—in other words, it’s like clicking with this tool at each point of the drag path and combining the results. This lets you easily fill an area occupied by a gradient or blur—just drag from the darkest to the lightest points in the area you want to fill:

-click and drag works similarly to simple drag, except from each point of the drag path, the fill spreads to the neighbors (if any) whose colors are similar to the color of the initial point (the point where you started the drag), not the point through which you’re dragging. This lets you fill a series of similarly colored yet separated areas (for example, multiple cells in a cartoon) by starting the drag in one of those areas and -dragging through all the other areas.

When looking for color boundaries to stop at, the Paint bucket looks by default at the colors as they are seen on the canvas. However, you can also restrict its vision to a specific color channel. The Fill by drop-down menu, apart from the default Visible Colors, allows you to choose any of the three RGB channels (Red, Green, Blue), any of the HSL channels (Hue, Saturation, Lightness), or the Alpha channel (opacity).

For example, if you select the Red channel, even the sharpest green/blue color boundaries won’t stop the fill. Choosing the Alpha channel makes the tool ignore any colors and only look at where opacity changes; for example, if you have a complex, multicolored, but fully opaque object over a transparent background, clicking this object in Alpha mode will fill up to the outline of the entire object.

The Threshold parameter, with a range from 0 to 100, controls how different a point’s color must be, compared to the initial click point, in order to stop the propagation of the fill. Zero tolerance means only the area of strictly the same color will be filled; the larger the tolerance, the larger the filled area will be, and the easier it will be for the fill to leak away into adjacent color areas. The default value is 10.

Using the Grow/shrink by parameter, you can control the amount of inset or outset (12.4 Offsetting) to be applied to the created fill path. It works much the same as the Outset and Inset path commands, except it’s done automatically after every fill.

A positive Grow/shrink value causes the fill path to be larger than the filled bitmap area it represents; this is often useful for eliminating anti-aliasing gaps between the fill and its boundary. A negative value makes the path smaller, ensuring a constant-width gap between the fill and the boundary.

With the Close gaps parameter, you can make the Paint bucket tool ignore any gaps in the area boundaries that would normally cause the fill to spill out of the desired area. There are four levels of automatic gap closing:

Like all object-creating tools, the Paint bucket can use the last set style (11.1.2 The Style of New Shapes) for the objects it creates (this is the default), or it can use its own fixed style. You can switch between these modes in the tool’s Inkscape Preferences (double-click the tool icon to access it). As with other tools, the style swatch on the far right of the controls bar shows the style that will be used for the next fill object you create. To change the last set color without affecting any object, just deselect () and click a color on the palette.

Clicking with turns the Paint bucket tool into a “single click styling” tool: Instead of filling an area, -clicking an object simply changes that object’s fill to the current fill color of the tool, and -clicking changes the stroke to the current stroke color of the tool. If no stroke is set, then -clicking behaves as -clicking.