ImageEn, unit imageenproc |
|
TImageEnProc.SetTransparentColors
Declaration
procedure SetTransparentColors(MinColor, MaxColor: TRGB; Alpha: Integer); overload;
procedure SetTransparentColors(Color: TRGB; Tolerance: Integer; Alpha: Integer); overload;
procedure SetTransparentColors(MinColor, MaxColor: TColor; Alpha: Integer); overload;
Description
Sets all pixels within the MinColor and MaxColor range as transparent. The level of transparency is specified by
Alpha (0=fully transparent, 255=fully visible).
If you have a specific transparent color, you can set MinColor and MaxColor to the same value. You can also use the second overload, to specify a transparent color and the Tolerance (0 - 255) to auto-calculate the color range.

Demo
| Demos\ImageEditing\MakeTransparent\MakeTransparent.dpr |
Example
// Specify all colors from gray (128, 128, 128) to white (255, 255, 255) as transparent
ImageEnView1.Proc.SetTransparentColors(CreateRGB(128, 128, 128), CreateRGB(255, 255, 255), 0);
// Make all colors close to white transparent
ImageEnView1.Proc.SetTransparentColors( TColor2TRGB( clWhite ), 20, 0 );
// Convert a bitmap where the bottom-left pixel represents the transparent color to a PNG
ImageEnView1.IO.LoadFromFile('D:\MakeTransparent.bmp');
// Get transparent color (transColor is type TRGB)
transColor := ImageEnView1.IEBitmap.Pixels[0, Height-1];
ImageEnView1.Proc.SetTransparentColors( transColor, transColor, 0 );
ImageEnView1.IO.SaveToFile('D:\NowTransparent.png');
// Example of drawing text with soft shadow over a background image
ImageEnView1.IO.LoadFromfile('background.jpg'); // load background image
ImageEnView1.LayersAdd; // add a new layer
ImageEnView1.IEBitmap.Canvas.Font.Name := 'Tahoma';
ImageEnView1.IEBitmap.Canvas.Font.Height := 45;
ImageEnView1.IEBitmap.Canvas.Font.Color := clYellow;
ImageEnView1.IEBitmap.Canvas.TextOut(0, 250, 'Hello World!'); // draw text on second layer
ImageEnView1.Proc.SetTransparentColors(CreateRGB(255, 255, 255), CreateRGB(255, 255, 255), 0); // remove the white, making it as transparent
ImageEnView1.Proc.AddSoftShadow(2, 3, 3); // add the shadow

See Also
-
CastAlpha-
CreateRGB-
TRGB2TColor-
TColor2TRGB