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 to 255, where 0 requires an exact color match, whereas 255 would match every color) to auto-calculate the color range.
Note:
◼If the image
PixelFormat is not one of ie24RGB, ie32RGB, ie1g, 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
| Demos\ImageEditing\MakeTransparent\MakeTransparent.dpr |
| Demos\ImageEditing\EveryMethod\EveryMethod.dpr |
// 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 to PNG where the bottom-left pixel represents the transparent color
bmp := TIEBitmap.Create;
bmp.LoadFromFile( 'D:\Glyph_Source.bmp');
// Get transparent color (transColor is type TRGB)
transColor := bmp.Pixels[ 0, bmp.Height - 1 ];
bmp.SetTransparentColors( transColor, transColor, 0 );
bmp.SaveToFile( 'D:\Glyph_Output.png');
bmp.Free;
Glyph_Source.bmp: | | |
Glyph_Output.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
// Load test image
ImageEnView1.IO.LoadFromFile( 'D:\TestImage.jpg' );
// Make colors similar to white transparent
ImageEnView1.Proc.SetTransparentColors( CreateRGB(255, 255, 255), 50, 0 );
// DRAW AN IMAGE ONTO ANOTHER
// Load our background image
ImageEnView1.IO.LoadFromFile( 'D:\Test2.png' );
// Load our foreground image
ImageEnView2.IO.LoadFromFile( 'D:\Temp\Cartoonify1.png' );
// Convert white background to alpha (transparent)
ImageEnView1.Proc.SetTransparentColors( clWhite, clWhite, 0 );
// Draw foreground image onto background image
bmp.DrawToTIEBitmap( ImageEnView1.IEBitmap, 0, 0 );
// Update the ImageEnView
ImageEnView1.Update();
See Also
◼CastAlpha
◼CreateRGB
◼TRGB2TColor
◼TColor2TRGB
◼TIEBitmap.SetTransparentColors