Skip to content

Instantly share code, notes, and snippets.

@drewmccormack
Created February 25, 2015 14:40
Show Gist options
  • Save drewmccormack/250542102aa77d700195 to your computer and use it in GitHub Desktop.
Save drewmccormack/250542102aa77d700195 to your computer and use it in GitHub Desktop.
Determine if a CGImage is fully opaque
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