ImageEn, unit iexBitmaps




function HasAlphaChannel(Validate: Boolean = False): boolean;


Specifies whether the current image has an alpha channel.

If Validate is False, HasAlphaChannel will return true even if the alpha channel is not used (image is completely opaque, but AlphaChannel is valid).
If Validate is true, it will check that the image uses the alpha channel, i.e. some parts of the image are transparent. The AlphaChannel is removed if not used.


if ImageEnView1.IEBitmap.HasAlphaChannel() then... // Image has alpha channel, may or may not be used

if ImageEnView1.IEBitmap.HasAlphaChannel( True ) then... // Image has alpha channel, part of the image are transparent

// Show the percentage of pixels that are partially or fully transparent
// Same as TImageEnProc.CalcImageNumColors()
  px: pbyte;
  y, x, l: integer;
  alphaCount, denom: Integer;
  bmp: TIEBitmap;
  bmp := ImageEnView1.IEBitmap;

  alphaCount := 0;
  if bmp.HasAlphaChannel() then
    l := IEBitmapRowLen( bmp.AlphaChannel.Width, bmp.AlphaChannel.BitCount, 8);
    for y := 0 to bmp.AlphaChannel.Height - 1 do
      px := bmp.AlphaChannel.Scanline[y];
      for x := 0 to l - 1 do
        if px^ < 255 then
          Inc( alphaCount );

  denom := bmp.Width * bmp.Height;
  ShowMessage( format( 'Image has %d%% transparent pixels', [ Round( alphaCount / denom * 100 )]));