0

Trying to find the best / easiest way using Objective C on MAC OSX if a PNG file has an Alpha Channel.

Filburt
  • 17,626
  • 12
  • 64
  • 115
ort11
  • 3,359
  • 4
  • 36
  • 69

2 Answers2

1

Here's one way:

NSBitmapImageRep *rep = [NSBitmapImageRep imageRepWithContentsOfFile:@"/path/to/image/test.png"];
BOOL alpha = [rep hasAlpha];
  • 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