Skip to content

Instantly share code, notes, and snippets.

@sag333ar
Created December 1, 2014 08:23
Show Gist options
  • Save sag333ar/e2907f32c0b86dd6f09d to your computer and use it in GitHub Desktop.
Save sag333ar/e2907f32c0b86dd6f09d to your computer and use it in GitHub Desktop.
Take screen-shot of UIWindow
- (UIImage *)getTheScreenShotFromWindow
{
// get the window size
UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
CGSize size = window.size;
// check the scale - retina or regular
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(size);
// get the context
window.rootViewController.view.layer renderInContext:UIGraphicsGetCurrentContext()];
// save the context to image
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// return the image
return image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment