Sets all pixels of the specified image to the color provided through the color parameter. See remarks for further details.

Namespace:  FreeImageAPI
Assembly:  FreeImageNET (in FreeImageNET.dll)


public static bool FillBackground<T>(
	T color,
where T : struct, new()
Visual Basic (Declaration)
Public Shared Function FillBackground(Of T As {Structure, New}) ( _
	dib As FIBITMAP, _
	color As T, _
) As Boolean
Visual C++
generic<typename T>
where T : value class, gcnew()
static bool FillBackground(
	T color, 


Type: FreeImageAPI..::.FIBITMAP
Handle to a FreeImage bitmap.
Type: T
The color to fill the bitmap with. See remarks for further details.
Options that affect the color search process for palletized images.

Type Parameters

The type of the specified color.

Return Value

true on success, false on failure.


This function sets all pixels of an image to the color provided through the color parameter. RGBQUAD is used for standard type images. For non standard type images the underlaying structure is used.

So, color must be of type Double, if the image to be filled is of type FIT_DOUBLE and must be a FIRGBF structure if the image is of type FIT_RGBF and so on.

However, the fill color is always specified through a RGBQUAD structure for all images of type FIT_BITMAP. So, for 32- and 24-bit images, the red, green and blue members of the RGBQUAD structure are directly used for the image's red, green and blue channel respectively. Although alpha transparent RGBQUAD colors are supported, the alpha channel of a 32-bit image never gets modified by this function. A fill color with an alpha value smaller than 255 gets blended with the image's actual background color, which is determined from the image's bottom-left pixel. So, currently using alpha enabled colors, assumes the image to be unicolor before the fill operation. However, the rgbReserved field is only taken into account, if option FICO_RGBA has been specified.

For 16-bit images, the red-, green- and blue components of the specified color are transparently translated into either the 16-bit 555 or 565 representation. This depends on the image's actual red- green- and blue masks.

Special attention must be payed for palletized images. Generally, the RGB color specified is looked up in the image's palette. The found palette index is then used to fill the image. There are some option flags, that affect this lookup process:

FICO_DEFAULT Uses the color, that is nearest to the specified color. This is the default behavior and should always find a color in the palette. However, the visual result may far from what was expected and mainly depends on the image's palette.
FICO_EQUAL_COLOR Searches the image's palette for the specified color but only uses the returned palette index, if the specified color exactly matches the palette entry. Of course, depending on the image's actual palette entries, this operation may fail. In this case, the function falls back to option FICO_ALPHA_IS_INDEX and uses the RGBQUAD's rgbReserved member (or its low nibble for 4-bit images or its least significant bit (LSB) for 1-bit images) as the palette index used for the fill operation.
FICO_ALPHA_IS_INDEX Does not perform any color lookup from the palette, but uses the RGBQUAD's alpha channel member rgbReserved as the palette index to be used for the fill operation. However, for 4-bit images, only the low nibble of the rgbReserved member are used and for 1-bit images, only the least significant bit (LSB) is used.

Version Information


Supported in: 3.13.0, 3.13.1

See Also