Trying to find the best / easiest way using Objective C on MAC OSX if a PNG file has an Alpha Channel.
Asked
Active
Viewed 1,511 times
2 Answers
1
Here's one way:
NSBitmapImageRep *rep = [NSBitmapImageRep imageRepWithContentsOfFile:@"/path/to/image/test.png"];
BOOL alpha = [rep hasAlpha];

Doug Lowder
- 26
- 3
-
Very nicely done. I am an iOS guy and I looked for something like this but could not find. Thanks Again.... – ort11 Jul 09 '15 at 00:00
0
If the color-type byte, which is at a known location within the IHDR chunk, is 0, 2, or 3 AND there is no tRNS chunk present before the first IDAT chunk, there is no alpha channel and the image is opaque. If a tRNS chunk is present, or if the color-type is 4 or 6, the image has an alpha channel, which might have transparency in some pixels or it might be opaque.

Glenn Randers-Pehrson
- 11,940
- 3
- 37
- 61
-
Thanks, was researching this. Was wondering if there was an API like in iOS with CGImage that has an api for YES or NO. – ort11 Jul 07 '15 at 21:33