ImageEn, unit imageenproc |
|
TImageEnProc.CastAlpha
Declaration
procedure CastAlpha(BmpX, BmpY: Integer; NewAlpha: Integer; Tolerance: Integer; SampleSize: Integer = 1; MaxFilter: Boolean = False; ColorFill: TColor = clNone);
Description
Perform a flood-fill starting at the bitmap coordinates
BmpX, BmpY, i.e. replacing all encountered pixels that match the color at the starting position with alpha.
Parameter | Description |
BmpX, BmpY | Pixel specifying the color to be made alpha |
NewAlpha | Specifies the Alpha level to apply to matching pixels in the range 0: Fully Transparent - 255: Opaque |
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") |
ColorFill | Specify to also fill the matching pixels with the specified color. The image must be ie24RGB |
Note:
◼To flood fill an area to a new color, use
CastColor
◼If the image
PixelFormat is not ie24RGB, it will be converted
◼An
AlphaChannel will be added to the image, if it does not exist
◼A UI for this is available to your users in the
Image Processing dialog
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 |
// Assuming X, Y are mouse coordinates, make the area transparent
ImageEnView1.Proc.CastAlpha( ImageEnView1.XScr2Bmp(X), ImageEnView1.YScr2Bmp(Y), 0, 0 );
// On mouse down flood fill the area opaque with a blue fill
procedure TForm1.ImageEnView1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ImageEnView1.Proc.CastAlpha( ImageEnView1.XScr2Bmp(X), ImageEnView1.YScr2Bmp(Y), 255, 0, 1, False, clBlue );
end;
// Load test image
ImageEnView1.IO.LoadFromFile( 'D:\TestImage.jpg' );
// Flood file transparency from the top-left of the image
ImageEnView1.Proc.CastAlpha( 0, 0, 0, 50 );
See Also
◼SetTransparentColors
◼CastColor