Skip to content

Instantly share code, notes, and snippets.

@balazsnemeth
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balazsnemeth/615b756b0bc68856e380 to your computer and use it in GitHub Desktop.
Save balazsnemeth/615b756b0bc68856e380 to your computer and use it in GitHub Desktop.
IPad screenshot
//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