Created
May 12, 2014 05:53
-
-
Save zengyun-hacker/69c79d1ff68ba34c56f8 to your computer and use it in GitHub Desktop.
make a screenshot and save it into UIImage
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
UIWindow *window = [UIApplication sharedApplication].keyWindow; | |
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { | |
UIGraphicsBeginImageContextWithOptions(window.bounds.size, NO, [UIScreen mainScreen].scale); | |
} | |
else { | |
UIGraphicsBeginImageContext(window.bounds.size); | |
} | |
if ([window respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) { | |
[window drawViewHierarchyInRect:window.bounds afterScreenUpdates:YES]; | |
} | |
else { | |
[window.layer renderInContext:UIGraphicsGetCurrentContext()]; | |
} | |
UIImage *scImage = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment