TIEBitmap.SyncAlphaChannel
Declaration
procedure SyncAlphaChannel(AntiAlias: Boolean = True);
Description
If you have manually loaded or set the
AlphaChannel, calling this method will ensure it matches the size of the image and has a pixelformat of ie8g (alpha channels with invalid sizes or color depths will not display).
AntiAlias specifies that a Bicubic filter is used if the alpha channel needs to be stretched (which will create a range of transparency values). Set to false to ensure an alpha channel with only 0 and 255 values (i.e. full alpha or full opaque pixels) will not have semi-transparent pixels.
Note: Use
Negative to invert the alpha channel (i.e. so black pixels become opaque and white transparent)
// Assign an alpha channel to an image using a source file
// For simple transparency, use a monochrome bitmap where the black pixels will become transparent
// Otherwise, a 256 color gray-scale image can provide a range of tranparency values (from white/fully opaque to black/fully transparent)
aBMP := TIEBitmap.create( 'D:\alpha.bmp' );
// Use our bitmap as the alpha channel
ImageEnView1.IEBitmap.AlphaChannel.Assign( aBMP );
// Ensure size of alpha channel matches size of image (and is ie8g)
ImageEnView1.IEBitmap.SyncAlphaChannel();
// Update the container
ImageEnView1.Update();
aBMP.Free();
Source ImageAlpha Image (Black will become transparent, gray will be 50% transparent and white will be fully opaque)
Result (on a white TImageEnView)
Example 2
// Create a shaped image, by drawing to the alpha channel
var aBmp := TIEBitmap.Create();
// Load our image content
aBmp.LoadFromFile( 'D:\fish.jpg' );
// Draw a shape to the alpha channel
aBmp.AlphaChannel.Fill( clBlack );
aBmp.AlphaChannel.FillWithShape( iesRadiance, -1, -1, clNone, 0, clWhite, False, True );
aBmp.SyncAlphaChannel(); // Fix the alpha channel
ImageEnView1.LayersAdd( aBmp ); // Do something with our image...
aBmp.Free();
See Also
◼AlphaChannel◼DetachAlphaChannel◼ReplaceAlphaChannel