Created
February 25, 2015 14:40
-
-
Save drewmccormack/250542102aa77d700195 to your computer and use it in GitHub Desktop.
Determine if a CGImage is fully opaque
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BOOL CGImageIsOpaque(CGImageRef image) | |
{ | |
size_t width = CGImageGetWidth(image); | |
size_t height = CGImageGetHeight(image); | |
unsigned char pixelData[width * height]; | |
CGContextRef context = CGBitmapContextCreate( pixelData, width, height, 8, width, NULL, (kCGBitmapAlphaInfoMask & kCGImageAlphaOnly) ); | |
CGContextDrawImage( context, CGRectMake(0, 0, width, height), image ); | |
CGContextRelease( context ); | |
for (NSInteger i = 0; i < width * height; ++i) { | |
if (pixelData[i] < 255) return NO; | |
} | |
return YES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment