TIEBitmap.SetTransparentColors
TIEBitmap.SetTransparentColors
Declaration
procedure SetTransparentColors(MinColor, MaxColor: TColor; Alpha: Integer); overload;
procedure SetTransparentColors(MinColor, MaxColor: TRGB; Alpha: Integer); overload;
procedure SetTransparentColors(Color: TRGB; Tolerance: Integer; 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 are sure of the transparent color, you can set MinColor and MaxColor to the same value.
// Specify all colors from gray (128, 128, 128) to white (255, 255, 255) as transparent
MyBMP.SetTransparentColors( CreateRGB(128, 128, 128), CreateRGB(255, 255, 255), 0 );
// Set all white pixels as transparent
MyBMP.SetTransparentColors( clWhite, clWhite, 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: | | |
// DRAW AN IMAGE ONTO ANOTHER
// Load our background image
ImageEnView1.IO.LoadFromFile( 'D:\_Testfiles\TestImages\Test2.png' );
// Load our foreground image
bmp := TIEBitmap.Create( 'D:\Temp\Cartoonify1.png' );
// Convert white background to alpha (transparent)
bmp.SetTransparentColors( clWhite, clWhite, 0 );
// Draw foreground image onto background image
bmp.DrawToTIEBitmap( ImageEnView1.IEBitmap, 0, 0 );
bmp.Free();
// Update the ImageEnView
ImageEnView1.Update();
See Also
◼CreateRGB
◼TRGB2TColor
◼TColor2TRGB