Reputation: 3349
Trying to find the best / easiest way using Objective C on MAC OSX if a PNG file has an Alpha Channel.
Upvotes: 0
Views: 1854
Reputation: 26
Here's one way:
NSBitmapImageRep *rep = [NSBitmapImageRep imageRepWithContentsOfFile:@"/path/to/image/test.png"];
BOOL alpha = [rep hasAlpha];
Upvotes: 1
Reputation: 12465
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.
Upvotes: 0