ImageEn, unit imageenview

TImageEnView.AlphaChannel

TImageEnView.AlphaChannel


Declaration

property AlphaChannel: TIEBitmap;


Description

Some formats like GIF, PNG, PSD, TIFF, ICO, CUR and TGA contain an alpha channel that specifies the image's transparency.
The alpha channel is stored in the AlphaChannel property (which just points to IEBitmap.AlphaChannel).




Example

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

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

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