RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCanvas.FloodFill Method

Fills an area of the canvas using the current brush.

Pascal
procedure FloodFill(X: Integer; Y: Integer; Color: TColor; FillStyle: TFillStyle);
C++
__fastcall FloodFill(int X, int Y, TColor Color, TFillStyle FillStyle);

Use FloodFill to fill a possibly non-rectangular region of the image with the value of Brush. The boundaries of the region to be filled are determined by moving outward from the point (X,Y) until a color boundary involving the Color parameter is encountered. 

X and X are the coordinates on the canvas where filling starts. 

Color is the color that defines the boundary of the region to fill. Its interpretation depends on the value of FillStyle. 

FillStyle specifies whether the region is defined by all pixels with the same value as Color, or all points with a different value.

Tip: Use the Pixels property to get the exact value of the color at the point (X,Y) when using a FillStyle of fsSurface. Similarly, when FillStyle is fsBorder, use Pixels to get the exact value of the boundary color if a point on the boundary is known.
 

C++ Examples: 

 

/*
The following code floodfills from the center point of
Form1's client area until the color black is encountered:
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Canvas->Brush->Color = clBlue;
  Canvas->Brush->Style = bsDiagCross;
  Canvas->FloodFill(
    ClientWidth/2, ClientHeight/2, clBlack, fsBorder);
}

void __fastcall TForm1::Button2Click(TObject *Sender)
{
  int ewidth = 400;
  int eheight = 200;
  Canvas->Brush->Color = clRed;
  Canvas->Pen->Color = clBlack;
  Canvas->Ellipse(
    (ClientWidth - ewidth)/2,
    (ClientHeight - eheight)/2, 
    ewidth, eheight);
}

 

Delphi Examples: 

{
The following code floodfills from the center point of 
Form1's client area until the color black is encountered:
}
procedure TForm1.Button1Click(Sender: TObject);
begin
  Canvas.Brush.Color := clBlue;
  Canvas.Brush.Style := bsDiagCross;
  Canvas.FloodFill(
    ClientWidth div 2, ClientHeight div 2, clBlack, fsBorder);
end;

procedure TForm1.Button2Click(Sender: TObject);
var ewidth, eheight: integer;
begin
  ewidth := 400;
  eheight := 200;
  Canvas.Brush.Color := clRed;
  Canvas.Pen.Color := clBlack;
  Canvas.Ellipse(
    (ClientWidth - ewidth) div 2, 
    (ClientHeight - eheight) div 2, 
    ewidth, eheight);
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!