Skip to content

Instantly share code, notes, and snippets.

@Arclite
Created December 21, 2011 01:10
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 Arclite/1504080 to your computer and use it in GitHub Desktop.
Save Arclite/1504080 to your computer and use it in GitHub Desktop.
Screenshot a view in iOS
UIGraphicsBeginImageContext([myView bounds].size);
UIGraphicsPushContext(UIGraphicsGetCurrentContext());
[[myView layer] renderInContext:UIGraphicsGetCurrentContext()];
UIGraphicsPopContext();
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
NSLog(@"screenshot data: %@", UIImagePNGRepresentation(screenshot)); //dumps a bunch of hex, use Hex Fiend to view it.
UIGraphicsEndImageContext();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment