FloodFill

procedure FloodFill(img: TImage32; x, y: Integer; newColor: TColor32; tolerance: Byte = 0; compareFunc: TCompareFunctionEx = nil);


FloodFill recolors pixels in the region defined by the starting pixel (x,y) and any adjacent pixels that closely match the starting pixel. Non-matching pixels form a barrier to further filling. If no CompareFunc is supplied, FloodFill will recolor pixels whose RGB values match the starting pixel within the specified tolerance.

Alternatively, the user can choose one of the predefined compare functions, CompareRGBEx or CompareAlphaEx, or even a custom compare function.

  uses Img32, Img32.Fmt.PNG, Img32.vector, Img32.Extra;
  ...
  var
    img: TImage32;
  begin
    img := TImage32.Create;
    img.LoadFromResource('BEETLE', 'PNG');
    FloodFill(img, 90,130, clLime32, 64);
    FloodFill(img, 140,110, clLime32, 64);
    img.SaveToFile('floodfill.png');
    img.Free;
  end;
    
Before:
After: