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 transparency in PNG file?

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 - Apr 04 2014 : 01:30:10
Hi! Is it possible to detect whether a .PNG file contains any transparent areas? The PNG file is always 32 bit with alpha channel - but may contain transparent areas or not. The pseudo code for this would be:

function PNGFileContainsTransparency(APNGFile: string): Boolean;
begin
  Result := False;
  if PNGFileIs32BitAlpha(APNGFile) then
    Result := PNGFileContainsTransparentArea(APNGFile);
end;
1   L A T E S T    R E P L I E S    (Newest First)
spetric Posted - Apr 04 2014 : 13:21:38
Hi,

I haven't try it, but, ImageEnProc.CalcImageNumColors may do the job, as, according to documentations it can be applied to any PixelFormat. So, it can be applied to alpha channel (8-bit image) as well.

If number of colors is equal to 1, alpha channel is filled with some single value (probably with 0xff). Otherwise, if number of colors is greater then 1, alpha channel has some other values, i.e. has some (semi)transparent areas.

If you're searching for full transparent areas (0x00), then you'll probably have to scan complete alpha channel and search for 0 value.

The good thing is, you need to fined only one pixel with 0 value and your task is finished. The worst scenario is that this pixel can be the last one scanned.