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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Detect transparency in PNG file?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

914 Posts

Posted - Apr 04 2014 :  01:30:10  Show Profile  Reply
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;

spetric

Croatia
308 Posts

Posted - Apr 04 2014 :  13:21:38  Show Profile  Reply
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.

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: