This one is tricky, since Apple does not provide you with an alternative API. There is one hidden in the header files however, replace:
.. bitsPerPixel = CGDisplayBitsPerPixel(CGMainDisplayID()); ..
with:
-- (size_t) displayBitsPerPixel:(CGDirectDisplayID) displayId { CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displayId); size_t depth = 0; CFStringRef pixEnc = CGDisplayModeCopyPixelEncoding(mode); if(CFStringCompare(pixEnc, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) depth = 32; else if(CFStringCompare(pixEnc, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) depth = 16; else if(CFStringCompare(pixEnc, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) depth = 8; return depth; } ... bitsPerPixel = [self displayBitsPerPixel: CGMainDisplayID() ]; ...
Thanks for the code! very helpful.
how about CGDisplayBytesPerpixel, do you have any suggestions?
Thanks for the code. It worked.
Thanks dude, this helped alot! Had no idea how to use the CFStringRef I got back from copyPixelEncoding!! Once again, thanks a bunch!
You’re leaking memory. You need to call:
CGDisplayModeRelease(mode);
CFRelease(pixEnc);