Created
December 1, 2014 08:23
-
-
Save sag333ar/e2907f32c0b86dd6f09d to your computer and use it in GitHub Desktop.
Take screen-shot of UIWindow
This file contains hidden or 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 *)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