ImageEn, unit imageenproc |
|
TImageEnProc.CastColor
Declaration
procedure CastColor(BmpX, BmpY: Integer; NewColor: TRGB; Tolerance: Integer; SampleSize: Integer = 1; MaxFilter: Boolean = False; NewAlpha: Integer = -1); overload;
procedure CastColor(BmpX, BmpY: Integer; NewColor: TColor; Tolerance: Integer; SampleSize: Integer = 1; MaxFilter: Boolean = False; NewAlpha: Integer = -1); overload;
Description
Perform a flood-fill starting at the bitmap coordinates
x, y, i.e. replacing all encountered pixels that match the color at the starting position with
NewColor.
Parameter | Description |
BmpX, BmpY | Pixel specifying the color to be replaced |
NewColor | Replacement color (if clNone, then the new color is not set) |
Tolerance | The maximum difference from the starting pixel (0 to 255, where 0 requires an exact color match, whereas 255 would match every color) |
SampleSize | The diameter of the area to sample (centered on BmpX, BmpY) to determine the seed color. If 1 is specified (Default) only the color of the specified pixel is used |
MaxFilter | Apply a maximum filter for more aggressive color selection (remove the "black hole") |
NewAlpha | Alpha value for any set colors, e.g. 255 to make all colored pixels fully opaque. Specify -1 to ignore the alpha channel |
Note:
◼To cast all pixels in the image, instead of flooding, use
CastColorRange
◼To flood fill an area with transparency, use
CastAlpha
◼If the image
PixelFormat is not ie24RGB or ie32RGB, it will be converted
CastColor vs CastAlpha
These methods can be used interchangeably.
// These two methods have the same effect (Flood filling Red)...
ImageEnView1.Proc.CastColor( x, y, clRed { NewColor }, 0, 1, False, -1 { NewAlpha } );
ImageEnView1.Proc.CastAlpha( x, y, -1 { NewAlpha }, 0, 1, False, clRed { NewColor } );
// These two methods have the same effect (Flood filling alpha to 125)...
ImageEnView1.Proc.CastColor( x, y, clNone { NewColor }, 0, 1, False, 125 { NewAlpha } );
ImageEnView1.Proc.CastAlpha( x, y, 125 { NewAlpha }, 0, 1, False, clNone { NewColor } );
// These two methods have the same effect (Flood filling Red with alpha of 255)...
ImageEnView1.Proc.CastColor( x, y, clRed { NewColor }, 0, 1, False, 255 { NewAlpha } );
ImageEnView1.Proc.CastAlpha( x, y, 255 { NewAlpha }, 0, 1, False, clRed { NewColor } );
| Demos\ImageEditing\EveryMethod\EveryMethod.dpr |
// Perform a red flood fill starting at 0,0 (with a tolerance of 10)
ImageEnView1.Proc.CastColor( 0, 0, clRed, 10 );
// When user clicks image, flood fill pixels of a similar color to white
procedure TForm1.ImageEnView1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if fColorCasting then
ImageEnView1.Proc.CastColor( ImageEnView1.XScr2Bmp(x), ImageEnView1.YScr2Bmp(y), CreateRGB(255, 255, 255), 10 );
end;
// Load test image
ImageEnView1.IO.LoadFromFile( 'D:\TestImage.jpg' );
// Perform a red flood fill starting at 0,0 (with a tolerance of 10)
ImageEnView1.Proc.CastColor( 0, 0, clRed, 10 );
See Also
◼Fill
◼CastAlpha