ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Detect number of transparent pixels in image?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
PeterPanino Posted - Dec 04 2021 : 18:35:28
Is there a FAST built-in function in TImageEnView to detect how many pixels inside an image are (more or less) transparent? (So I could calculate the percentage of transparent areas in the image).
2   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Dec 19 2021 : 22:56:42
In v10.3.1 there will be a new method, TImageEnProc.CalcImageTransparency

Nigel
Xequte Software
www.imageen.com
xequte Posted - Dec 10 2021 : 00:05:30
There is not, but the code would be as follows:

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;


Nigel
Xequte Software
www.imageen.com