Note: You must be registered in order to post a reply. To register, click here. Registration is FREE!
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.