Skip to content

Instantly share code, notes, and snippets.

@jmenter
Created December 22, 2014 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmenter/91e8eed4104bf58e83a1 to your computer and use it in GitHub Desktop.
Save jmenter/91e8eed4104bf58e83a1 to your computer and use it in GitHub Desktop.
Get CGContextRef from a UIView's CALayer's contents (assuming contents is a CGImageRef)
CGImageRef image = (__bridge CGImageRef)self.view.layer.contents;
CGDataProviderRef dataProviderRef = CGImageGetDataProvider(image);
CFDataRef dataRef = CGDataProviderCopyData(dataProviderRef);
void *dataBytePointer = (void *)CFDataGetBytePtr(dataRef);
CGColorSpaceRef colorSpace = CGImageGetColorSpace(image);
CGContextRef context = CGBitmapContextCreateWithData(dataBytePointer, CGImageGetWidth(image), CGImageGetHeight(image), CGImageGetBitsPerComponent(image), CGImageGetBytesPerRow(image), colorSpace, CGImageGetBitmapInfo(image), NULL, NULL);
CGContextDoWhatever(context)...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment