Last active
August 29, 2015 14:14
-
-
Save balazsnemeth/615b756b0bc68856e380 to your computer and use it in GitHub Desktop.
IPad screenshot
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
//Create an image about the screen of the iOS device | |
+ (UIImage *) screenshot{ | |
UIWindow *mainWindow = [[[UIApplication sharedApplication] windows] firstObject]; | |
if(UIGraphicsBeginImageContextWithOptions != NULL) | |
{ | |
UIGraphicsBeginImageContextWithOptions(mainWindow.frame.size, NO, 0.0f); | |
} else { | |
UIGraphicsBeginImageContext(mainWindow.frame.size); | |
} | |
//Get all the views with the same size! | |
for (UIWindow *window in [[UIApplication sharedApplication] windows] ) { | |
if (CGSizeEqualToSize(window.frame.size, mainWindow.frame.size)) { | |
[window drawViewHierarchyInRect:mainWindow.frame afterScreenUpdates:YES]; | |
} | |
} | |
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return image; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment