ImageEn, unit iexBitmaps

TIEBitmap.SyncAlphaChannel

TIEBitmap.SyncAlphaChannel


Declaration

procedure SyncAlphaChannel(AntiAlias: Boolean = True; ClearHiddenContent: Boolean = False);


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.
If ClearHiddenContent is enabled, any content that has an alpha value of 0 (is not visible) will be set to white. This will not affect the image that is visible, but will optimize the image save save for formats that support Alpha, like PNG (this is the same as enabling AutoOptimizeOnSave).



Note: Use Negative to invert the alpha channel (i.e. so black pixels become opaque and white transparent)


Example

// 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 Image




Alpha 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();



Example 3

// Optimize a PNG image (by clearing any non-visible content)
ImageEnView1.IO.LoadFromFile( 'D:\Image.png' );
ImageEnView1.IEBitmap.SyncAlphaChannel( True, True );
ImageEnView1.IO.SaveToFile( 'D:\Image_Optimized.png' );


See Also

AlphaChannel
DetachAlphaChannel
ReplaceAlphaChannel