Created
December 7, 2012 13:15
-
-
Save zapsleep/4233212 to your computer and use it in GitHub Desktop.
UIKit screenshot snippet
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
- (UIImage*)screenshotFromView:(UIView *)view | |
{ | |
CGSize imageSize = [view bounds].size; | |
if (NULL != UIGraphicsBeginImageContextWithOptions) | |
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0); | |
else | |
UIGraphicsBeginImageContext(imageSize); | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
CGContextSaveGState(context); | |
CGContextTranslateCTM(context, | |
[view center].x, | |
[view center].y); | |
CGContextConcatCTM(context, [view transform]); | |
CGContextTranslateCTM(context, | |
-[view bounds].size.width * [view anchorPoint].x, | |
-[view bounds].size.height * [view anchorPoint].y); | |
[view renderInContext:context]; | |
CGContextRestoreGState(context); | |
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return image; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment