Skip to content

Instantly share code, notes, and snippets.

@zengyun-hacker
Created May 12, 2014 05:53
Show Gist options
  • Save zengyun-hacker/69c79d1ff68ba34c56f8 to your computer and use it in GitHub Desktop.
Save zengyun-hacker/69c79d1ff68ba34c56f8 to your computer and use it in GitHub Desktop.
make a screenshot and save it into UIImage
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