FreeImage.FillBackground(T) Method

FreeImage.NET

FreeImageFillBackgroundT Method
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) Version: 3.17.0.4 (3.17.0)
Syntax
C#
public static bool FillBackground<T>(
	FIBITMAP dib,
	T color,
	FREE_IMAGE_COLOR_OPTIONS options
)
where T : struct, new()

Parameters

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

Type Parameters

T
The type of the specified color.

Return Value

Type: Boolean
true on success, false on failure.
Remarks
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 [!:FREE_IMAGE_COLOR_OPTIONS.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:

ValueMeaning
[!:FREE_IMAGE_COLOR_OPTIONS.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.
[!:FREE_IMAGE_COLOR_OPTIONS.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 [!:FREE_IMAGE_COLOR_OPTIONS.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.
[!:FREE_IMAGE_COLOR_OPTIONS.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.

See Also